使用Python抓取此网站时出错

使用Python抓取此网站时出错,python,web-scraping,Python,Web Scraping,我很难从你那里获取一些信息。我主要尝试检索“当前条件”信息表。 这是我到目前为止得到的,但它给了我一些错误 import urllib2 from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(urllib2.urlopen('http://www.timeanddate.com/weather/usa/los-angeles').read()) for row in soup('table', {'class' : 'rpad

我很难从你那里获取一些信息。我主要尝试检索“当前条件”信息表。 这是我到目前为止得到的,但它给了我一些错误

import urllib2
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://www.timeanddate.com/weather/usa/los-angeles').read())

for row in soup('table', {'class' : 'rpad'})[0].tbody('trtd'):
tds = row('tr')
print tds.string
我的解决方案,运行时的输出如下所示:

None
Location:
Los Angeles / USC Campus Downtown
Temperature:
63 °F
Comfort Level:
63 °F
Dew point:
51 °F
Pressure:
29.94 "Hg
Humidity:
65%
Visibility:
10 mi
Wind:
No wind
Last update:
Sun 7:47 PM PDT
没有花额外的时间为第一次输出添加None检查,因为我累了。当然,也没有明显的格式,但是你自己加入也不会太难


希望这对您有所帮助。

您能提供您收到的错误,包括回溯吗?回溯上一次调用:文件C:\Users\Andrew\Desktop\test.py,第8行,在soup'table'中的for行,{'class':'rpad'}[0].tbody'trtd':TypeError:'NoneType'对象不可调用我不确定我做错了什么如果您不介意通过单击上下投票箭头下方的复选标记接受我的答案,我将不胜感激。
None
Location:
Los Angeles / USC Campus Downtown
Temperature:
63 °F
Comfort Level:
63 °F
Dew point:
51 °F
Pressure:
29.94 "Hg
Humidity:
65%
Visibility:
10 mi
Wind:
No wind
Last update:
Sun 7:47 PM PDT