Python:BeautifulSoup.find_all()打印空[]?

Python:BeautifulSoup.find_all()打印空[]?,python,class,parsing,beautifulsoup,findall,Python,Class,Parsing,Beautifulsoup,Findall,我正试图通过以下方式从地下世界获取预测的高温/低温: from bs4 import BeautifulSoup from urllib2 import urlopen zipcode = raw_input("Type in your zipcode: ") url_end = zipcode + ".1.99999" base_url = "http://www.wunderground.com/weather-forecast/zmw:" + url_end my_html = url

我正试图通过以下方式从地下世界获取预测的高温/低温:

from bs4 import BeautifulSoup
from urllib2 import urlopen
zipcode = raw_input("Type in your zipcode: ")
url_end = zipcode + ".1.99999"

base_url = "http://www.wunderground.com/weather-forecast/zmw:" + url_end

my_html = urlopen(base_url)
html_text = my_html.read()
my_soup = BeautifulSoup(html_text)

high = my_soup.find_all("span", class_="high")

low = my_soup.find_all("span", class_="low")

print high
它会问你的zip,你给它,它会吐回网页上显示的所有预测的高/低温度,但是我是BS4的新手,我显然把
搞砸了。find_all()
,因为我只得到了空括号:

[]

我很清楚一旦运行,我需要清理结果。

网页正在用javascript更新,因此结果不在页面元素中

对于站点的工作方式,最好使用split和json,或者对站点进行更深入的分析,以找到用于返回站点上使用的javascript框架数据的调用

或者只使用api:

基本上它是空的,因为javascript更新页面上的元素

但是,您可以使用selenium之类的工具打开页面并运行javascript


然后,您的呼叫将按预期工作。

为什么在
之后会有
?这是打字错误吗?@Anzel这是BS4的语法,因为命名冲突。啊,酷,我通常使用字典,避免夸尔格,干杯。顺便问一下,站点是否在没有用户代理的情况下阻止请求?检查您的
html\u文本
响应,您可以尝试添加一个,然后查看。如果不阻止请求,我可以更改high=my\u soup。。。。位到类似于打印my_soup.title或其他标记名的位置,它就工作了。@CharlesWatson,你能在
html_文本
中显示部分结果吗?在
span
中,类
high
/
low
,并确保它们存在吗?