AttributeError: 'NoneType' object has no attribute 'findAll' while scrapimg from wikipedia
AttributeError: 'NoneType' object has no attribute 'findAll' while scrapimg from wikipedia
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'])
当我 运行 此代码时出现错误。
这是我收到的错误;
Traceback (most recent call last):
File "C:/Users/shubham/PycharmProjects/testday1/scrapping/lamdaexp.py", line 9, in
for link in bsobj.find("div",{"id":"bodycontent"}).findAll("a", href = re.compile("^(/wiki/)((?!:).)*$")):
AttributeError: 'NoneType' object has no attribute 'findAll'
请帮我解决这个问题。这是在一个 youtube 视频教程中,在教程视频中 运行 没问题,而在我的 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'])
当我 运行 此代码时出现错误。 这是我收到的错误;
Traceback (most recent call last): File "C:/Users/shubham/PycharmProjects/testday1/scrapping/lamdaexp.py", line 9, in for link in bsobj.find("div",{"id":"bodycontent"}).findAll("a", href = re.compile("^(/wiki/)((?!:).)*$")): AttributeError: 'NoneType' object has no attribute 'findAll'
请帮我解决这个问题。这是在一个 youtube 视频教程中,在教程视频中 运行 没问题,而在我的 PyCharm 中显示此错误。
ID 是 bodyContent
而不是 bodycontent
。
C!不是c.