我试图用BeautifulSoup刮一个网站,但我有一个问题。 我在Python 2.7中完成了一个教程,它有完全相同的代码,并没有问题。Python:AttributeError:'NoneType'对象没有属性'findNext'
import urllib.request
from bs4 import *
htmlfile = urllib.request.urlopen("http://en.wikipedia.org/wiki/Steve_Jobs")
htmltext = htmlfile.read()
soup = BeautifulSoup(htmltext)
title = (soup.title.text)
body = soup.find("Born").findNext('td')
print (body.text)
如果我尝试运行该程序,我得到,
Traceback (most recent call last):
File "C:\Users\USER\Documents\Python Programs\World Population.py", line 13, in <module>
body = soup.find("Born").findNext('p')
AttributeError: 'NoneType' object has no attribute 'findNext'
这是与Python 3有问题还是我太天真?
你确定你不想'body = soup.find('body')'? –