【发布时间】:2019-03-07 06:24:16
【问题描述】:
我正在尝试从 Google 的 7 天预报中获取风速。当我检查网页代码时,我可以看到风速,但是当我在课堂上使用 find_all() 时,它只返回温度数据和来自 7 天预报的今天风速。
import requests
from bs4 import BeautifulSoup
page = requests.get("https://www.google.co.nz/search?ei=CQmzW9_zHsaiwAPuvruwCQ&q=tauranga+weather+forecast&oq=tauranga++forecast&gs_l=psy-ab.3.0.0i7i30k1l10.9062.9062.0.11810.1.1.0.0.0.0.205.205.2-1.1.0....0...1c.1.64.psy-ab..0.1.205....0.R-r6_9AWgnA")
soup = BeautifulSoup(page.content, "html.parser")
wind = soup.find_all("span", class_="wob_t")
for i, e in enumerate(wind):
print(i, e.get_text())
我在这里做错了什么?
【问题讨论】:
-
如果布局更改,您的应用程序将中断。考虑改用天气 API。
-
我同意 alexander.. 但只是为了好玩,为“e”类的 div 做一个 find_all。您将到达风跨度所在的div
标签: python python-3.x beautifulsoup python-requests