【发布时间】:2014-01-29 03:24:35
【问题描述】:
我正在尝试使用 BeautifulSoup 抓取网站,但遇到了问题。 我正在学习一个在 python 2.7 中完成的教程,它的代码完全相同,没有任何问题。
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')?
标签: python web-scraping beautifulsoup