pik*_*kuu 3 python beautifulsoup
到目前为止这是我的代码
# -*- encoding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup as bs
import json
data = urllib2.urlopen('http://www.jma.go.jp/en/yoho/320.html')
html_doc = data.read()
soup = bs(html_doc)
weather = soup.find('table',attrs={'class':'forecast'})
weather_res = weather.find_all('th')
Run Code Online (Sandbox Code Playgroud)
为什么我得到NoneType错误...
看起来你很混淆Beautiful Soup 3和4,你正在导入版本3,但是使用find_all了版本4的功能.这个功能在版本3中是findAll.所以如果你想继续使用版本3,你需要将其重写为:
weather_res = weather.findAll('th')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1569 次 |
| 最近记录: |