Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35837

Re: how to get the source of html in lxml?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.042
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'received:209.85.223': 0.03; 'url:blog': 0.09; 'cc:addr:python-list': 0.10; 'dec': 0.15; 'skip:f 30': 0.15; 'urllib': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'code,': 0.18; 'import': 0.21; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'run': 0.28; 'source': 0.29; 'code': 0.31; 'skip:b 40': 0.32; 'print': 0.32; 'yours,': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'several': 0.39; 'header:Received:5': 0.40; '30,': 0.62; 'subject:get': 0.81; '10:32': 0.84; 'sender:addr:chris': 0.84; 'subject:source': 0.84; 'url:cn': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=hUzD1A+TdoPB2/2NsNbMwcGeAVvN/QDVFihpLTKaoi0=; b=LFKgwkcyDgrn9DMG3+TtwrxuUd23qdOiD0mCOEYe/C2fvnGt6aWpIgL9GchXk2rxPp fM6AE4tF7gAUOsL1+zPMHLiDKNB1dQdummwJYjNEhagXm0LcAWvpscvrnx7vkkcpqEHd E2qrXPj7idYF2MKRMCkKd/qzTtsStIQZLMc8o=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=hUzD1A+TdoPB2/2NsNbMwcGeAVvN/QDVFihpLTKaoi0=; b=UBHzSQvG7UrjYiawT9jJl5X6ZXVzSxQPAtg6sPTC47UYr4byPxrzAVg058wUhwWb1W lfuXODV1KKsN087XXPjh5wIdZi4DoedG4TRtpDiYx6OXLi2HG0j/WKfHi3voD5H5bI7B wQCYT4VR5uUNdd2HG43QQv1oakxQY5hzxfpxDeIlfaCREdgeCZt1YpUntrbtEFzpw1DA qQb2dVUnpARu5HD0ZBblf4ly4afaQMFQ3ufogFvAEMHlVP55spSAvgP8xB6OuE7giZ9u z7UrZKaCeNHxii5pHI9dEmLtGVOjMN1P4GEd7IhtMw7iIuCOMVqIRC6PBZ6ArV3c1qPR lxbw==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <CA+YdQ_4oFo7GfntaSxzdVsLCUSwgwJgdJrwVabgrUVbzPHKJcA@mail.gmail.com>
References <CA+YdQ_4oFo7GfntaSxzdVsLCUSwgwJgdJrwVabgrUVbzPHKJcA@mail.gmail.com>
Date Sun, 30 Dec 2012 22:48:12 -0800
X-Google-Sender-Auth DnkX3UtTNFfS7fw5KlsQLbs_kaw
Subject Re: how to get the source of html in lxml?
From Chris Rebert <clp2@rebertia.com>
To contro opinion <contropinion@gmail.com>
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQl+T144y99qvHgPGIyFg9Tct9mGmCWb1NFavMuXo446mdjWqNgybzbt4eIs6jRs9VNXwxIO
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1488.1356936500.29569.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356936500 news.xs4all.nl 6911 [2001:888:2000:d::a6]:38174
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35837

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to get the source of html in lxml? Chris Rebert <clp2@rebertia.com> - 2012-12-30 22:48 -0800

csiph-web