【问题标题】:AttributeError: 'NoneType' object has no attribute 'find_all' when scraping wikiAttributeError:“NoneType”对象在抓取 wiki 时没有属性“find_all”
【发布时间】:2018-09-01 01:48:16
【问题描述】:
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' 对象没有属性 'find_all'。有谁知道这个有什么问题吗?

【问题讨论】:

    标签: python-3.x web-scraping beautifulsoup wikipedia


    【解决方案1】:

    您的脚本中有几个简单的错误:

    1. 从您的 url 字符串中删除最后一个正斜杠 (/)。

    url = 'https://en.wikipedia.org/wiki/Berlin_Wall'

    1. td 在您的循环中不存在,因此将其更改为 tr
    print(tr.text)
    

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2016-05-06
      • 1970-01-01
      相关资源
      最近更新 更多