Python 3.x 属性错误:';非类型';对象没有属性';findAll';而维基百科上的scrapimg
当我运行这段代码时,我得到了一个错误。 这就是我得到的错误 回溯(最近一次呼叫最后一次): 文件“C:/Users/shubham/PycharmProjects/testday1/scrasting/lamdaexp.py”,第9行,在 对于bsobj.find(“div”,“id”:“bodycontent”}).findAll(“a”,href=re.compile(^(/wiki/)((?!:)*$)中的链接: AttributeError:“非类型”对象没有属性“findAll”Python 3.x 属性错误:';非类型';对象没有属性';findAll';而维基百科上的scrapimg,python-3.x,web-scraping,attributeerror,Python 3.x,Web Scraping,Attributeerror,当我运行这段代码时,我得到了一个错误。 这就是我得到的错误 回溯(最近一次呼叫最后一次): 文件“C:/Users/shubham/PycharmProjects/testday1/scrasting/lamdaexp.py”,第9行,在 对于bsobj.find(“div”,“id”:“bodycontent”}).findAll(“a”,href=re.compile(^(/wiki/)((?!:)*$)中的链接: AttributeError:“非类型”对象没有属性“findAll” 请帮
请帮我做这个。这是在youtube视频教程中,它在教程视频中运行良好,而在my PyCharm中,它显示此错误。ID是
bodyContent
,而不是bodyContent
。
C不是c
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
html = urlopen("https://en.wikipedia.org/wiki/Kevin_Bacon")
bsobj = BeautifulSoup(html,'lxml')
for link in bsobj.find("div",{"id":"bodycontent"}).findAll("a", href =
re.compile("^(/wiki/)((?!:).)*$")):
if 'href' in link.attrs:
print(link.attrs['href'])