小编Bra*_*rad的帖子

beautifulsoup"列表对象没有属性"错误

我正在尝试使用以下方法从天气现场刮取温度:

    import urllib2
from BeautifulSoup import BeautifulSoup

f = open('airport_temp.tsv', 'w')

f.write("Location" + "\t" + "High Temp (F)" + "\t" + "Low Temp (F)" + "\t" + "Mean Humidity" + "\n" )

eventually parse from http://www.wunderground.com/history/airport/\w{4}/2012/\d{2}/1/DailyHistory.html

for x in range(10):
    locationstamp = "Location " + str(x)
    print "Getting data for " + locationstamp
    url = 'http://www.wunderground.com/history/airport/KAPA/2013/3/1/DailyHistory.html'

    page = urllib2.urlopen(url)
    soup = BeautifulSoup(page)

    location = soup.findAll('h1').text
    locsent = location.split()
    loc = str(locsent[3,6]) 

    hightemp = soup.findAll('nobr')[6].text
    htemp = hightemp.split()
    ht …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

python ×1

web-scraping ×1