Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35839 > unrolled thread
| Started by | Dave Angel <d@davea.name> |
|---|---|
| First post | 2012-12-31 01:51 -0500 |
| Last post | 2012-12-31 01:51 -0500 |
| 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? Dave Angel <d@davea.name> - 2012-12-31 01:51 -0500
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-12-31 01:51 -0500 |
| Subject | Re: how to get the source of html in lxml? |
| Message-ID | <mailman.1490.1356936724.29569.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web