473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML DOM parser?

Is there an HTML DOM parser available for Python? Preferably one that
does a reasonable job with the crappy HTML out there on real web
pages, that doesn't get upset about unterminated tables and stuff like
that. Many extra points if it understands Javascript. Application is
a screen scraping web robot. Thanks.
Jul 18 '05 #1
6 12407
adfgvx wrote:
Try tidy. There are two python wrappers : mxtidy and utidy, the latest is
Where can we get utidy?
more recent and use the new tidylib. BUT it will only correct a bad html
page and transform it to an xml or xhtml output that you load after as a DOM
with another parser. Personnaly I use pyRXP.


Bye,
Walter Dörwald

Jul 18 '05 #2
Paul Rubin <http://ph****@NOSPAM.invalid> writes:
Is there an HTML DOM parser available for Python? Preferably one that
does a reasonable job with the crappy HTML out there on real web
pages, that doesn't get upset about unterminated tables and stuff like
that. Many extra points if it understands Javascript. Application is
a screen scraping web robot. Thanks.


glork. I just started working on this myself.

Email me if you'd like the code, such as it is. I've wrapped the
Mozilla JS interpreter but am currently stuck on a segfault, so I
could certainly do with a collaborator.

I'm using utidylib and 4DOM (latter from PyXML).

Mind you, if you actually want to get a job done <wink>, for a
quick-but-bulky (and somewhat closed) solution, try PyKDE (KHTML /
KJS) or IE automation (MSHTML / JScript). Mozilla + XPCOM also, but I
think it requires rebuilding Mozilla to get PyXPCOM support. There's
also httpunit (in Java, useable from Jython).
John
Jul 18 '05 #3
mailto:gi****@pilotsystems.net
"Paul Rubin" <http://ph****@NOSPAM.invalid> a écrit dans le message de news:
7x***************@ruckus.brouhaha.com...
Is there an HTML DOM parser available for Python? Preferably one that
does a reasonable job with the crappy HTML out there on real web
pages, that doesn't get upset about unterminated tables and stuff like
that. Many extra points if it understands Javascript. Application is
a screen scraping web robot. Thanks.


Windoze IE5(+) + Win32All python package only :

Use IE as COM object, browse the file or URL, then, get it's DOM root.
But any javascript found in that page is executed at page load and may fool
your app.

--Gilles

Jul 18 '05 #4
ca*****@yahoo.com writes:
Here is a quick example of using automation with IE
# This is a sample of automating IE using Python.


Thanks, I should have said I'm running under gnu/linux and I was
hoping for a standalone solution (some of the ones suggested sound
worth looking into). Even connecting up Python to Mozilla sounds
awfully heavyweight.
Jul 18 '05 #5
Paul Rubin <http://ph****@NOSPAM.invalid> writes:
ca*****@yahoo.com writes:
Here is a quick example of using automation with IE
# This is a sample of automating IE using Python.


Thanks, I should have said I'm running under gnu/linux and I was
hoping for a standalone solution (some of the ones suggested sound
worth looking into). Even connecting up Python to Mozilla sounds
awfully heavyweight.


PyKDE is less hassle, I think. It's certainly heavyweight, though.
Probably more lightweight still is HttpUnit on Jython. I haven't used
either, but I have compiled PyKDE recently, and didn't run into
problems (but if you're unlucky, you may have to compile Qt, KDE, sip
and PyQt first!).

I seem to have got a basic JavaScript wrapper working now (I'm using
libjs from Mozilla's standalone spidermonkey distribution), bound 4DOM
to it, and extracted & executed the script from a web page. Quite a
lot more to do, though (browser-like interface of some sort,
javascript: scheme URLs, implement window object, wiring up event
attributes to the JS interpreter, getting the DOM actually working
propertly, understanding what document.write does, trying to connect
the DOM to my Python HTML form and HTTP cookies interfaces...).

Anybody happen to know where JavaScript's document.some_form is
documented? Official W3C DOM has document.forms, but real browser
DOMs apparently have forms directly on the document object.
John
Jul 18 '05 #6
jj*@pobox.com (John J. Lee) wrote in message news:<87************@pobox.com>...
Paul Rubin <http://ph****@NOSPAM.invalid> writes:
ca*****@yahoo.com writes:
Here is a quick example of using automation with IE
# This is a sample of automating IE using Python.


Thanks, I should have said I'm running under gnu/linux and I was
hoping for a standalone solution (some of the ones suggested sound
worth looking into). Even connecting up Python to Mozilla sounds
awfully heavyweight.


PyKDE is less hassle, I think. It's certainly heavyweight, though.
Probably more lightweight still is HttpUnit on Jython. I haven't used
either, but I have compiled PyKDE recently, and didn't run into
problems (but if you're unlucky, you may have to compile Qt, KDE, sip
and PyQt first!).

I seem to have got a basic JavaScript wrapper working now (I'm using
libjs from Mozilla's standalone spidermonkey distribution), bound 4DOM
to it, and extracted & executed the script from a web page. Quite a
lot more to do, though (browser-like interface of some sort,
javascript: scheme URLs, implement window object, wiring up event
attributes to the JS interpreter, getting the DOM actually working
propertly, understanding what document.write does, trying to connect
the DOM to my Python HTML form and HTTP cookies interfaces...).

Anybody happen to know where JavaScript's document.some_form is
documented? Official W3C DOM has document.forms, but real browser
DOMs apparently have forms directly on the document object.
John


Try here: http://msdn.microsoft.com/library/de...ence_entry.asp
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2577
by: YoBro | last post by:
Hi I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form...
4
2437
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad...
0
2711
by: Himanshu Garg | last post by:
Hello, I am using HTML::Parser to extract text from html pages from http://bbc.co.uk/urdu/ However the encoding of the input text seems to change to some unknown encoding in the output. The...
3
3108
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
4
4391
by: bariole | last post by:
Hi I am trying to make lexical analysis of some simplified html code with flex tool. However that kind of work is new to me and I don't know where to start. I have searched a web but I didn't...
82
6218
by: Eric Lindsay | last post by:
I have been trying to get a better understanding of simple HTML, but I am finding conflicting information is very common. Not only that, even in what seemed elementary and without any possibility...
8
2378
by: Lachlan Hunt | last post by:
Hi, I'm interested in finding out how erroneous comment syntax within an HTML document should be handled by a parser, according to SGML rules. At present, every browser handles comments in...
2
2649
by: David Virgil Hobbs | last post by:
Loading text strings containing HTML code into an HTML parser in a Javascript/Jscript I would like to know, how one would go about loading a text string containing HTML code, so as to be able to...
0
1978
by: june | last post by:
Hi, I have a big problem with parsing HTML into a XHTML using Cberneko to validate the html. First I tried to work with a HTML-File. This solutions works fine: String aHTMLFile =...
4
1912
by: Jackie | last post by:
Hi, all, I want to get the information of the professors (name,title) from the following link: "http://www.economics.utoronto.ca/index.php/index/person/faculty/" Ideally, I'd like to have a...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.