【发布时间】:2019-12-25 01:37:27
【问题描述】:
使用soup.find提取表数据时,变量表返回NoneType。错误是:“NoneType”对象没有“查找”属性。来自网站的类名如下图所示,所以并不是我使用了错误的类名。我不确定我做错了什么,感谢任何帮助。
import requests
from bs4 import BeautifulSoup
url = "https://www.wunderground.com/history/monthly/KATL/date/2019-12"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table = soup.find("table",{"class":"days ng-star-inserted"})
table_body = table.find('tbody')
【问题讨论】:
-
您是否检查了该类是否也存在于请求返回的 HTML 中?
-
好吧,看来表确实是动态创建的。我相信这是返回数据的请求:
https://api.weather.com/v1/location/KATL:9:US/observations/historical.json?apiKey=6532d6454b8aa370768e63d6ba5a832e&units=e&startDate=20191201&endDate=20191231.
标签: python html web-scraping beautifulsoup