Python: Scrape pages and extract information

I was amazed at how incredibly easy it was to scrape pages using Python.

To download the page markup, use:

import urllib
content = urllib.urlopen("http://finance.google.com/finance?q=IBM").read()

Once you have the content, simply use regex to parse the bit you want.

import re
m = re.search('class="pr".*?>(.*?)<', content)

if m:
quote = m.group(1)

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog