0

When requesting a website using class='even', I end up just receiving '[]' as my result.

import requests
import urllib.request
import time
from bs4 import BeautifulSoup

url = 'https://www.worldometers.info/coronavirus/'
response = requests.get(url)

soup = BeautifulSoup(response.text, 'html.parser')
print(soup.findAll('tr', class_='even'))

This is my result

[]

I tried looking in a lot of places but I couldn't find out why. The HTML code is really long as there is a lot of data.

1 Answers1

0

I am not sure that this is the universal solution, but this is what worked for my project. I used @ahmedamerican's solution with a few changes in order to fix it.

import requests
import pandas as pd
import lxml

r = requests.get("https://www.worldometers.info/coronavirus/")
df = pd.read_html(r.content)[0]

print(df)

Just instead of doing print(type(df)) as he said, I did print(df).

  • my answer was actually guiding you to `print(df)`, i just was shown the type of the object to let you understand it's a `dataframe`, also you don't need to import `lxml`. it's already included within `pandas` library. However my answer has been deleted by the `Moderator` because it's count as duplicated, as I've answered the same [question](https://stackoverflow.com/questions/61008195/how-to-construct-data-frame-from-web-scraping-in-python/61008983#61008983) before. – αԋɱҽԃ αмєяιcαη Apr 03 '20 at 15:15