遇到的问题:
代码编译后出现AttributeError: ‘NoneType’ object has no attribute 'text’错误
Traceback (most recent call last):
File "E:/Python/src/sd.py", line 28, in <module>
content=get_content(url)
File "E:/Python/src/sd.py", line 12, in get_content
content=texts.text.strip().split('\xa0'*4)
AttributeError: 'NoneType' object has no attribute 'text'
分析:
target='https://www.xsbiquge.com/15_15338/'
req=requests.get(url=target)
req.encoding='utf-8'
html=req.text
chapter_bs=BeautifulSoup(html,'lxml')
chapters=chapter_bs.find('div',id='content')
id写错导致没有找到text
将content改为list即可。要明确爬取的标签