Welcome to Foundation of Data Science Laboratory
Welcome to Foundation of Data Science Laboratory
Program 1: Find and print all the links in the page
Program 2: Identify a website with tabular data (e.g., a Wikipedia table).
Program 3: Find and print all article titles
Program 4: 1. Parsing a Simple HTML Document
Program 5: Finding Elements by Tag
Program 6: Finding an Element by Class Name
Program 7: Extracting Attributes from a Tag
Program 8: Navigating HTML with Parent and Sibling Relationships
Step 1: Install Required Libraries
pip install requests beautifulsoup4 pandas
Step 2: Write the Python Code import requests
from bs4 import BeautifulSoup
import pandas as pd
import requests
# Step 1: Identify the URL of the website with tabular data
url = "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"
# Step 2: Send a request to fetch the webpage content
response = requests.get(url)
# Step 3: Parse the webpage content using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')
# Step 4: Locate the table you want to scrape (use inspect tool to find the right table)
table = soup.find('table', {'class': 'wikitable'})