# pip install readability-lxml
# pip install html2text
import requests
from readability import Document
import html2text
response = requests.get('http://www.infzm.com/content/146720')
doc = Document(response.text)
print(doc.title())
content = html2text.html2text(doc.summary())
print(content)
"""
readability可以在不使用xpath,re等时,自动识别返回的response中的标题,正文等。但是正文时常会有html标签
html2text可以处理掉文字中的html标签,
"""
"""
可以这样使用忽略标签属性的干扰
h=html2text.HTML2Text()
h.ignore_links=True
print h.handle("<p>Hello, <a href='http://earth.google.com/'>world</a>!") # 输出Hello world
"""
另外还有newspaper
也与readability相似。