【发布时间】:2019-02-15 09:35:44
【问题描述】:
我正在尝试将table 抓取到数据框中。我的尝试只返回表名,而不是每个区域的行内的数据。
这是我目前所拥有的:
from bs4 import BeautifulSoup as bs4
import requests
url = 'https://www.eia.gov/todayinenergy/prices.php'
r = requests.get(url)
soup = bs4(r.text, "html.parser")
table_regions = soup.find('table', {'class': "t4"})
regions = table_regions.find_all('tr')
for row in regions:
print row
我想要得到的理想结果:
region | price
---------------|-------
new england | 2.59
new york city | 2.52
感谢您的帮助。
【问题讨论】:
标签: python dataframe web-scraping beautifulsoup