Example of web parser


/ Published in: Python
Save to your folder(s)

Simple web parser using urllib and re libs.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.