import urllib
import lxml.html
down='http://blog.sina.com.cn/s/blog_71f3890901017hof.html'
file=urllib.urlopen(down).read()
root=lxml.html.document_fromstring(file)
body=root.xpath('//div[@class="articalContent "]')[0]
print body.text_content()
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我得到的是文本内容,我如何获得它的html源代码,而不是文本内容?
小智 5
使用
html = lxml.html.tostring(node)
Run Code Online (Sandbox Code Playgroud)
并请:先阅读您正在使用的工具的基本文档.
| 归档时间: |
|
| 查看次数: |
2344 次 |
| 最近记录: |