473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 12405
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.