f=open("galcode.txt")
for element in f:
galcode_scan = re.search(ur'http://i\.imgur\.com/\w{5,8}', element)
if galcode_scan:
print galcode_scan.groups()
f.close()
Galcode.txt in this instance is html of a gallery on imgur. I am trying to get a list of all the links to a gallery that gets posted to imgur. If I run this after inputting the gallery name and recieving the galcode all I get is about 15 (). How do I get the list of links?
Thanks
You do not have any capture groups, so .groups()
is returning an empty tuple. Use .group()
instead or surround your regex with parentheses (ur'(http://i\.imgur\.com/\w{5,8})'
).
That said, I strongly suggest using something like BeautifulSoup, cssselect or any other HTML parsing library.