Posted By

zhyar on 10/01/12


Tagged

python web parser


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dimusixus
icecreamboyy


Example of web parser


 / Published in: Python
 

Simple web parser using urllib and re libs.

  1. import urllib, re
  2.  
  3. url = 'http://www.viedemerde.fr/aleatoire'
  4. page = urllib.urlopen(url).read()
  5. parse = re.findall("\<div class=\"post article\" id=\"(.+?)\">(.+?)</div", page)
  6. for article in parse:
  7. parse1 = re.findall("\<a href=\"(.+?)" + article[0] + "\" class=\"fmllink\">(.+?)</a>", article[1])
  8. vdm = ''
  9. for test in parse1:
  10. vdm += test[1]
  11. print("http://viedemerde.fr/"+article[0]+" : "+vdm)

Report this snippet  

You need to login to post a comment.