import re
import urllib
p = urllib.urlopen("http://sprunge.us/QZhU")
page = p.read()
pos = page.find("<h2><span>")
print page[pos:pos+48]
c = re.compile(r'<h2><span>(.*)</span>')
print c.match(page).group(1)
When I run it:
shadyabhi@archlinux $ python2 temp.py
<h2><span>House.S08E02.HDTV.XviD-LOL.avi</span>
Traceback (most recent call last):
File "temp.py", line 8, in <module>
print c.match(page).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
shadyabhi@archlinux $
If I can find a string using string.find then what is the problem when I use regex. I have tried looking http://docs.python.org/howto/regex.html#regex-howto but no help.