Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35837 > unrolled thread
| Started by | Chris Rebert <clp2@rebertia.com> |
|---|---|
| First post | 2012-12-30 22:48 -0800 |
| Last post | 2012-12-30 22:48 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: how to get the source of html in lxml? Chris Rebert <clp2@rebertia.com> - 2012-12-30 22:48 -0800
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2012-12-30 22:48 -0800 |
| Subject | Re: how to get the source of html in lxml? |
| Message-ID | <mailman.1488.1356936500.29569.python-list@python.org> |
On Sun, Dec 30, 2012 at 10:32 PM, contro opinion <contropinion@gmail.com> wrote:
> 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()
>
> When i run the code, what i get is the text content ,how can i get the html
> source code of it?
print lxml.html.tostring(body)
Did you read through the lxml.html documentation?
http://lxml.de/lxmlhtml.html
It includes several examples that make use of lxml.html.tostring().
RTFineM-ly Yours,
Chris
Back to top | Article view | comp.lang.python
csiph-web