Python 如何在lxml中获取html的源代码?
当我运行代码时,我得到的是文本内容,如何获得它的html源代码,而不是文本内容?使用Python 如何在lxml中获取html的源代码?,python,lxml,Python,Lxml,当我运行代码时,我得到的是文本内容,如何获得它的html源代码,而不是文本内容?使用 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="articalCont
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()
请先阅读您正在使用的工具的基本文档
html = lxml.html.tostring(node)