Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Possible to obtain root element from lxml?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeroen Janssens  
View profile  
 More options May 10 2012, 2:11 pm
From: Jeroen Janssens <jer...@jeroenjanssens.com>
Date: Thu, 10 May 2012 11:11:53 -0700 (PDT)
Local: Thurs, May 10 2012 2:11 pm
Subject: Possible to obtain root element from lxml?

Dear all,

Let me start by saying that Beautiful Soup 4 is a wonderful package. I have
used BS4 to implement a script that extracts the main text from a news
article and it works great, especially with Unicode. That script is now
being merged with a bunch of other scripts that use plain lxml and no BS4.

In terms of efficiency, it would be best if the html would only be parsed
once. There may be two possibilities to accomplish this. First, BS4 could
be given the tree as parsed by lxml. Second, the tree should be obtainable
once BS4 has processed and parsed the html. I think that the former is not
possible since BS4 does some Unicode magic to the html (correct me if I'm
wrong about this). So I'm now hoping that the latter is possible.

I have looked at the source code of BS4 (builder/_lxml.py) and at the lxml
documentation. The documentation mentions that after the parser has been
fed some markup, parser.close() should return the root element. However,
I'm only getting "None". Any help on this or some other way to parse the
html only once is much appreciated. Thank you.

Best wishes,

Jeroen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.