【发布时间】:2019-06-04 19:25:11
【问题描述】:
我不确定为什么在使用 BeautifulSoup 在 WebScraping 上运行 Python 2 中的代码时收到错误消息 AttributeError: 'NoneType' object has no attribute 'text'?
错误信息:
AttributeError Traceback(最近调用 最后)
在 ()
----> 1 个名称 = name_box.text.strip()
AttributeError: 'NoneType' 对象没有属性 'text'
以下是我的代码:
from bs4 import BeautifulSoup
import requests
import csv
source = requests.get('http://coreyms.com').text
soup = BeautifulSoup(source, 'lxml')
name_box = soup.find('h1', attrs = {'class': 'name'})
name = name_box.text.strip()
你能帮忙吗?谢谢!
【问题讨论】:
标签: python beautifulsoup python-requests