[Python]新手爬虫问题
rom bs4 import BeautifulSoupimport requests
url='https://jingyan.baidu.com/article/cbf0e500ad03222eaa2893a1.html'
A=requests.get(url)
soup=BeautifulSoup(A.text,'lxml')
lit=soup.find('ol',{'class':"exp-conent-orderlist"})
l=lit.find_all_next('li')
v=[]
for i in l:
v = i.find('div',{'class':"content-list-text"}).strip()
print(v)
这段代码最后一段v = i.find('div',{'class':"content-list-text"}).strip()..如果我在.strip之前加一个get_text()的话会报错一下
File "F:/Python自制软件/爬虫1号!.py", line 11, in <module>
v = i.find('div',{'class':"content-list-text"}).get_text().strip()
AttributeError: 'NoneType' object has no attribute 'get_text'
但是内容可以显示
但是如果去掉(我上面展示的代码)的话
Traceback (most recent call last):
File "F:/Python自制软件/爬虫1号!.py", line 11, in <module>
v = i.find('div',{'class':"content-list-text"}).strip()
TypeError: 'NoneType' object is not callable
直接错误了,根本没有爬取... 再遍历L之前,你可以输出一下,我猜是空
页:
[1]