0

im not sure what is wrong and why beautifulsoup cannot find the tr class. What am I doing wrong or where should I look?

 import requests
 from bs4 import BeautifulSoup

 URL = "https://www.dailyfx.com/economic-calendar#yesterday"
 page = requests.get(URL)
 soup = BeautifulSoup(page.content, 'html.parser')

 tbody = soup.find("tbody", class_ = "dfx-font-size-4")

 column = tbody.find("tr", class_= "dfx-expandableTable__row dfx- 
 economicCalendarRow__pastEvent")

 td = column.find("td", class_="dfx-economicCalendarRow__countryCol jsdfx- 
 economicCalendarRow__countryCol align-top")

 div = td.find("div", class_="dfx-economicCalendarRow__countryContent dfx- 
 expandableTable__fadeableContent  dfx-border--y-0 dfx-border--l-0 text-nowrap pe-lg-6 
 w-100")

 country = div.find("span", class_="dfx-economicCalendarRow__country jsdfx- 
 economicCalendarRow__country align-middle text-black font-weight-bold d-none d-lg- 
 inline").text

 print(country)

here is the error:

Traceback (most recent call last): File "c:\Users\Economic Event Scraper\test.py", line 12, in td = column.find("td", class_="dfx-economicCalendarRow__countryCol jsdfx-economicCalendarRow__countryCol align-top") AttributeError: 'NoneType' object has no attribute 'find'

  • Please update your question with the full error traceback. This usually gives you a starting place to look. – quamrana Dec 17 '22 at 16:12
  • there is no `dfx-expandableTable__row dfx-economicCalendarRow__pastEvent` class in your `column`. – JayPeerachai Dec 17 '22 at 16:12
  • Perhaps you want to find `tr` with class `dfx-expandableTable__row` only (without the `dfx- economicCalendarRow__pastEvent`)? The code works that way. Though it seems the `country` is empty string. – NoThlnG Dec 17 '22 at 16:15
  • Traceback (most recent call last): File "c:\Users\Economic Event Scraper\test.py", line 12, in td = column.find("td", class_="dfx-economicCalendarRow__countryCol jsdfx-economicCalendarRow__countryCol align-top") AttributeError: 'NoneType' object has no attribute 'find' – Vibe Improvement Dec 17 '22 at 16:21

0 Answers0