import requests from bs4 import BeautifulSoup import pandas as pd # Send a GET request to the SEMrush website url = 'https://www.semrush.com/website/top/argentina/all/' response = requests.get(url) # Parse the HTML content of the response using BeautifulSoup soup = BeautifulSoup(response.content, 'html.parser') # Find the table containing the data table = soup.find('table', {'class': 'table table--separate-rows'}) # Extract the data from the table and store it in a pandas DataFrame data = [] for row in table.find_all('tr'): cols = row.find_all('td') cols = [col.text.strip() for col in cols] data.append(cols) df = pd.DataFrame(data[1:], columns=data[0]) # Print the DataFrame print(df)
import requests from bs4 import BeautifulSoup import pandas as pd # Send a GET request to the SEMrush website url = 'https://www.semrush.com/website/top/argentina/all/' response = requests.get(url) # Parse the HTML content of the response using BeautifulSoup soup = BeautifulSoup(response.content, 'html.parser') # Find the table containing the data table = soup.find('table', {'class': 'table table--separate-rows'}) # Extract the data from the table and store it in a pandas DataFrame data = [] for row in table.find_all('tr'): cols = row.find_all('td') cols = [col.text.strip() for col in cols] data.append(cols) df = pd.DataFrame(data[1:], columns=data[0]) # Print the DataFrame print(df)