Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.094 X-Spam-Evidence: '*H*': 0.82; '*S*': 0.01; 'url:blog': 0.09; 'skip:f 30': 0.15; 'to:name:python-list': 0.15; 'urllib': 0.16; 'code,': 0.18; 'import': 0.21; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'source': 0.29; 'code': 0.31; 'skip:b 40': 0.32; 'print': 0.32; 'received:74.125.82': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'skip:b 50': 0.35; 'subject:?': 0.35; 'received:74.125': 0.36; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'subject:get': 0.81; 'subject:source': 0.84; 'url:cn': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=7XjLeMrCCNl8VweyxdED4/o2Y3kY2Hb2OvJS8KX8RDE=; b=a/naIltH3N9qb9PhA66C9i1vgrOsBgjjHZg3vQITaZGMJqE09v4bgYIVVf/4fiRIvK 1qqiAIJ27lyT3tP7Rz/TFKfgGIMxXNXEEVGHcskENaRqxDVY/uTcPYttz7xum4aFclcO wcqMaE3K1cjLwz/RcgkEeXdENr9XkROkLM2VotnghI/F7Kg/BMrgU9LZ25bVdrZ5IArH TikY2jb5sS0zWH3G07q+WXRD+aa3FWN7iNzNRg/P6LRmt1smZ5YLbG5j16kvPwYJCGEt J32uvjNxPsEBe9ifu9UIsZtMYYPkLbzYBPxOjhBiZaBxfUljVN9ZklLEudrMtDpShUXK iP2g== MIME-Version: 1.0 Date: Mon, 31 Dec 2012 14:32:01 +0800 Subject: how to get the source of html in lxml? From: contro opinion To: python-list Content-Type: multipart/alternative; boundary=f46d0445182dc1db5b04d2202bfe X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356935528 news.xs4all.nl 6857 [2001:888:2000:d::a6]:58068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35834 --f46d0445182dc1db5b04d2202bfe Content-Type: text/plain; charset=ISO-8859-1 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? --f46d0445182dc1db5b04d2202bfe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
import urllib
import lxml.html
down=3D'http://blog.sina.=
com.cn/s/blog_71f3890901017hof.html'
file=3Durllib<=
span class=3D"pun">.urlopen(down).<=
span class=3D"pln">read()
root=3Dlxml.html.document_fromstring=
(file)
body=3Droot.xpath('//div[@class=3D"articalContent  &qu=
ot;]')[0]
print body.text_content()

When i run the code, what i get is the text content ,how can i get the h= tml source code of it?

--f46d0445182dc1db5b04d2202bfe--