zy820
2017-03-14 08:21Python string.replace()
#coding=utf-8
import re
from bs4 import BeautifulSoup as BS
import requests
import hackhttp
# BeautifulSoup
url='https://www.douyu.com/directory/game/LOL'
r=requests.get(url,verify=False)
html=r.content
soup=BS(html,'lxml')
bbs=soup.find_all(name='h3',attrs={'class':'ellipsis'})
print bbs
for news in bbs:
print news.string.replace('\r','').replace('\n','')
结果:
Traceback (most recent call last):
File "spider.py", line 18, in <module>
print news.string.replace('\r','').replace('\n','')
**AttributeError: 'NoneType' object has no attribute 'replace'**
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 字符串到UCS-2
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 3个回答
- 将来自控制台的字符串输入片段转换为数字片段
- slice
- type-conversion
- 2个回答
- 当源代码包含多个级别/目录时部署Google Cloud Function
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- 从字符串中删除无效的UTF-8字符
- json
- unicode
- 2个回答
- 用正则表达式包装字符串中的单词
- php
- 3个回答
换一换