Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35839
| Date | 2012-12-31 01:51 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: how to get the source of html in lxml? |
| References | <CA+YdQ_4oFo7GfntaSxzdVsLCUSwgwJgdJrwVabgrUVbzPHKJcA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1490.1356936724.29569.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how to get the source of html in lxml? Dave Angel <d@davea.name> - 2012-12-31 01:51 -0500
csiph-web