u013928906
zy820
2017-03-14 08:21

Python string.replace()

  • python
 #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条回答

为你推荐

换一换