how to get the source of html in lxml?
Dave Angel
d at davea.name
Mon Dec 31 01:51:47 EST 2012
More information about the Python-list mailing list
Mon Dec 31 01:51:47 EST 2012
- Previous message (by thread): how to get the source of html in lxml?
- Next message (by thread): the class problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 12/31/2012 01:32 AM, contro opinion wrote: > import urllibimport 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() > > When i run the code, what i get is the text content ,how can i get the html > source code of it? > > That's got several syntax errors, but if you remove the parts with errors, you'll find the html source in the misnamed variable 'file'. The read() method returns a string. -- DaveA
- Previous message (by thread): how to get the source of html in lxml?
- Next message (by thread): the class problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list