Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing Webpages in Python
#1
Tutorial on parsing HTML(and XML) in Python:


What is parser?(From Wikipedia)
The most common use of a parser is as a component of a compiler or interpreter. This parses the source code of a computer programming language to create some form of internal representation.

What is the point of this tutorial?
Learning how to grab any piece of information you want off any webpage, efficiently and easily.


Section 1 - Basics of HTML tags, attributes & difference from XML (Click to View)

Section 2 - Source from a webpage with Python (Click to View)

Section 3 - Basics of the LXML module, and the DOM (Click to View)

Section 4 - Using what you learned (Click to View)
[Image: sig.php]
Reply
#2
This is coming along nicely so far, Nyx-, just tell me when you're finished and I'll take another read. I'm itching to learn Python now.
<Aoi-chan> everyone's first vi session. ^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat
Reply
#3
Can't wait to see it finished...
I was looking for this and you're going straight into my direction, thanks!

Will be checking this later.. to see if you have it finished ;)
Reply
#4
Awesome Big Grin

I never really touched any parsers and just stuck with regex and logic lol, but this seems really handy ^_^
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply
#5
(01-20-2010, 04:05 PM)Master of The Universe Wrote: Can't wait to see it finished...
I was looking for this and you're going straight into my direction, thanks!

Will be checking this later.. to see if you have it finished ;)

hehe awesome, yea its finished now. PLEASE PLEASE PLEASE read it and tell me if theres any parts i need to go more in detail in, or parts that have typos, are ugly, ect so I can try and improve it ^__^. Having a web developer see if my tutorial is understandable would be perfect, atleast for the web development parts.
[Image: sig.php]
Reply
#6
Ahh just pure knowledge, it's really easy to understand and I also don't see any kind of mistakes... for now ;)
I was following your tutorial, then I changed urllib to urllib2, now a question.... when does it matter which lib I use...?

Also I do it like Fallen and use regex, idk... it's better imo... ;)
I'm writting here a little script that I'll only be able to finish because of this tutorial, I'll post it later....

Thanks for the share....
Reply
#7
(01-23-2010, 08:20 PM)Master of The Universe Wrote: Ahh just pure knowledge, it's really easy to understand and I also don't see any kind of mistakes... for now ;)
I was following your tutorial, then I changed urllib to urllib2, now a question.... when does it matter which lib I use...?

Also I do it like Fallen and use regex, idk... it's better imo... ;)
I'm writting here a little script that I'll only be able to finish because of this tutorial, I'll post it later....

Thanks for the share....

uhh i know they have some different functions ect, but for just opening up a link to read i dont think there would be much difference, you can look at the urllib library page and urllib2 and see what they added on, but i couldn't say forsure tbh
[Image: sig.php]
Reply
#8
Yeah I'm looking at both oin the Docs... I'm not sure but it looks like the urllib2 has functions for cookie handling and such things... idk just started looking at Big Grin

But so far, your tut helped me understand the basics, I'm just now playing with different sites than just PB... Tongue
Reply
#9
(01-24-2010, 05:07 PM)Master of The Universe Wrote: Yeah I'm looking at both oin the Docs... I'm not sure but it looks like the urllib2 has functions for cookie handling and such things... idk just started looking at Big Grin

But so far, your tut helped me understand the basics, I'm just now playing with different sites than just PB... Tongue

yea hopefully you can help me on better "global" gallery rules ^_^, a.k.a. better way to grab gallery pictures from more then just a single site. what i did was parse for every link that ended in a .jpg, .gif, .png ect, then added it to a list and it wouldnt add more then one of a link into the list of direct links, but whats even harder is figuring out a good global rule to go to the next page in a gallery, cause on PB i use a get request which is terrible since i doubt a get request is going to be even similar over all, i'd have to think of a decent parsing rule to grab a next page button or something.
[Image: sig.php]
Reply
#10
Ahh I know what you mean now...
I can think of a way maybe, but I'll check it out first...
I will go through few HTML sources along with the PB ones and look for any smiliar codes...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,003 09-30-2019, 12:59 AM
Last Post: samsmith001
  Parsing text files for keywords/class names and arguments kemen 1 1,033 01-02-2013, 08:47 AM
Last Post: Rhynorater
  Simple Python Python Compiler Canoris 21 9,174 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,661 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 890 02-12-2010, 09:07 PM
Last Post: Kharnage

Forum Jump:


Users browsing this thread: 1 Guest(s)