AttributeError: 'NoneType' object has no attribute 'find_all' when scraping wiki
AttributeError: 'NoneType' object has no attribute 'find_all' when scraping wiki
from bs4 import BeautifulSoup
import requests
import lxml
url = 'https://en.wikipedia.org/wiki/Berlin_Wall/'
cream = requests.get(url).content
soup= BeautifulSoup(cream, 'lxml')
table = soup.find('table', {'class' : 'infobox vcard'})
type(table)
table_rows = table.find_all('tr')
for tr in table_rows:
print(td.text)
我正在使用 python3。我试图从维基百科页面中删除信息框,但不断收到 AttributeError: 'NoneType' object has no attribute 'find_all'。任何人都知道这个问题是什么?
您的脚本中有几个简单的错误:
- 从 url 字符串中删除最后一个正斜杠 (
/
)。
url = 'https://en.wikipedia.org/wiki/Berlin_Wall'
td
在您的循环中不存在,因此将其更改为 tr
:
print(tr.text)
from bs4 import BeautifulSoup
import requests
import lxml
url = 'https://en.wikipedia.org/wiki/Berlin_Wall/'
cream = requests.get(url).content
soup= BeautifulSoup(cream, 'lxml')
table = soup.find('table', {'class' : 'infobox vcard'})
type(table)
table_rows = table.find_all('tr')
for tr in table_rows:
print(td.text)
我正在使用 python3。我试图从维基百科页面中删除信息框,但不断收到 AttributeError: 'NoneType' object has no attribute 'find_all'。任何人都知道这个问题是什么?
您的脚本中有几个简单的错误:
- 从 url 字符串中删除最后一个正斜杠 (
/
)。
url = 'https://en.wikipedia.org/wiki/Berlin_Wall'
td
在您的循环中不存在,因此将其更改为tr
:
print(tr.text)