|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- rom bs4 import BeautifulSoup
- import 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
复制代码
直接错误了,根本没有爬取... |
|