当前位置: 首页 > 后端技术 > Python

python爬虫遇到AttributeError错误怎么办?

时间:2023-03-26 13:09:30 Python

python爬虫出现AttributeError:'NoneType'objecthasnoattribute'text'错误,怎么办?项目场景:Python爬虫爬小说(Jackcui网络爬虫教学实例)问题描述:遇到的问题:AttributeError:'NoneType'objecthasnoattribute'text'代码编译后报错traceback(最近调用last):File"E:/Python/src/sd.py”,第28行,在content=get_content(url)文件“E:/Python/src/sd.py”,第12行,在get_contentcontent=texts.text.strip().split('xa0'*4)AttributeError:'NoneType'objecthasnoattribute'text'原因分析:分析:target='https://www.xsbiquge.com/15_15338/'req=requests.get(url=target)req.encoding='utf-8'html=req.textchapter_bs=BeautifulSoup(html,'lxml')chapters=chapter_bs.find('div',id='content')id错误导致未找到文本解决方案:只需将内容更改为列表即可。搞清楚爬虫标签,推荐看:适合初学者的PythonIDE有哪些?