Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.053 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.01; 'syntax': 0.03; 'string.': 0.04; 'url:blog': 0.09; 'errors,': 0.09; 'read()': 0.09; 'skip:f 30': 0.15; 'wrote:': 0.17; 'code,': 0.18; 'variable': 0.20; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'run': 0.28; 'source': 0.29; 'code': 0.31; 'skip:b 40': 0.32; 'to:addr:python-list': 0.33; 'text': 0.34; 'subject:?': 0.35; 'but': 0.36; 'method': 0.36; 'subject:: ': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'remove': 0.61; "you'll": 0.62; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'subject:get': 0.81; 'received:74.208.4.194': 0.84; 'subject:source': 0.84; 'url:cn': 0.97 Date: Mon, 31 Dec 2012 01:51:47 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: how to get the source of html in lxml? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:UaSMdUVUa8YSmymos2/h0UwZl80a8EhzK/MSfVI5w1G gxqb4gSEK3zYvimXN5Q94KDPsGQHjhpB7dAvlphiZza9acMd3w K9UXTA8Y5Jf2A3YgOVAqmHxjq2rbYmrK56lg3uKkNgmt5xqQM6 l9KYLtaX+2LA1I7RwLa1e477MfKY/IpsKqEhsQ6WdoVW6cqohz j6DKU1bW3HLaqrdW2XJr9cWSsiS5aJg0N3llCR1NN6Km7TT3RQ kxTx5DNKNyUDZU6lMHcithxZ2rxdjnbjfcVh/+YdcPEyWvwz27 nUy4WJi6dt04nYl31YAkbtBRrUe9rFEVWLIurNku7hjp6vNGA= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: d@davea.name 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356936724 news.xs4all.nl 6922 [2001:888:2000:d::a6]:40693 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35839 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