嗨,我一直在尝试使用 BeautifulSoup 从 wunderground 获取一张桌子,但它不起作用。
我认为这可能是表格标题旁边的星形字符串,但我无法修复它。
这是我的代码:
from bs4 import BeautifulSoup
import requests
url='https://www.wunderground.com/history/daily/LEMD/date/2020-10-21'
html_content = requests.get(url).text
soup = BeautifulSoup(html_content, "html.parser")
table = soup.find("table", {"class": "mat-table cdk-table mat-sort ng-star-inserted"})
table_data = table.tbody.find_all("tr")
和错误:
Traceback (most recent call last):
File "weather_poc.py", line 12, in <module>
table_data = table.tbody.find_all("tr")
AttributeError: 'NoneType' object has no attribute 'tbody'