Я пытался извлечь содержимое из таблицы на веб-сайте.
descriptions = []
sources = []
values = []
site = 'https://www.eia.gov/todayinenergy/prices.php' #address of the site
driver = webdriver.Chrome(executable_path=r"chromedriver.exe")
driver.execute_script("document.body.style.zoom='100%'")
driver.get(site)
soup_1 = bs(driver.page_source, 'lxml') #clean up the site using beautiful soup
tables = soup_1.find_all('tbody') #script of interest
print(len(tables)) #count the scripts
for table in tables:
rows = table.find_all('tr')
print(len(rows))
for row in rows:
description = row.find('td', class_='s1')
descriptions.append(descri_clean)
source = row.find('td', class_='s2')
sources.append(source_clean)
value = row.find('td', class_='d1') #find the row that gives the data
values.append(value_clean) #compile it all together
driver.close()
Я пытался получить чистый текст из таблицы, однако извлеченные данные выглядят так.
<td class="s1" rowspan="3">Crude Oil<br/> ($/barrel)</td>
Пока я хочу что-то вроде «сырой нефти» ($ / баррель)
Когда я пытался
description = row.find('td', class_='s1').text.renderContents()
descriptions.append(descri_clean)
Ошибка обнаружилась
AttributeError: 'NoneType' object has no attribute 'renderContents'