#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'**