4. Using Regular Expressions, scrape the Gas Concentration Table that was scraped in question #2. The first step is to scrape the complete webpage using Beautifulsoup and then use regex to parse the Gas Concentration Table html page.
question 2:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://en.wikipedia.org/wiki/Greenhouse_gas"
res = requests.get(url)
soup = BeautifulSoup(res.content, "html.parser")
# Find the table of interest
table = soup.find("table", {"class": "wikitable sortable"})
# Extract the header and data rows
header = [th.text.strip() for th in table.find("tr").find_all("th")]
data = [[td.text.strip() for td in tr.find_all("td")] for tr in table.find_all("tr")[1:]]
# Create the DataFrame
df = pd.DataFrame(data, columns=header)
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://en.wikipedia.org/wiki/Greenhouse_gas"
res = requests.get(url)
soup = BeautifulSoup(res.content, "html.parser")
# Find the table of interest
table = soup.find("table", {"class": "wikitable sortable"})
# Extract the header and data rows
header = [th.text.strip() for th in table.find("tr").find_all("th")]
data = [[td.text.strip() for td in tr.find_all("td")] for tr in table.find_all("tr")[1:]]
# Create the DataFrame
df = pd.DataFrame(data, columns=header)
![4. Using Regular Expressions, scrape the Gas Concentration Table that was scraped in question #2.
The first step is to scrape the complete webpage using Beautifulsoup and then use regex to parse
the Gas Concentration Table html page.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5483afab-7850-40f6-959f-e698dea1419a%2F25b8a73a-c2f6-4e59-a2c2-00b5bdc68cd3%2Fnp3o6bk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Please refer to the following step for the complete solution to the problem above.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)