For Loops in Python to read Long URL from shortened URL -
i'm python beginner , struggling loop function. if run code receive long url last entry. ideas? thanks
import urllib2 beautifulsoup import beautifulsoup x in ('civ8jguveh','isrohi98ag','taz38yubob'): shorturl = 'http://t.co/' + str(x) output = urllib2.urlopen(shorturl) print output.url
you reassigning variable every time before opening or printing url. need indent code assigning , printing output
variable done within loop:
import urllib2 beautifulsoup import beautifulsoup x in ('civ8jguveh','isrohi98ag','taz38yubob'): shorturl = 'http://t.co/' + str(x) output = urllib2.urlopen(shorturl) print output.url
Comments
Post a Comment