Open URL using variable or data file

Hi, i’m getting how to get this work.

I’m trying to open URL from a source file or a variable. but i don’t know how it works.

here’s a screenshot of the result i’m getting:


Thank you

nevermind, i found a solution from this post



Old style string concatenation can be used

id = “3333333”
url = “” % id
print url

The new style string formatting:

url = “{0}”.format(id)
print url

The reading for file as mentioned by avasal with a small change:

f = open(‘file.txt’, ‘r’)
for line in f.readlines():
id = line.strip(’\n’)
url = “{0}”.format(id)
urlobj = urllib.urlopen(url)
json_data = json.loads(urlobj)
print json_data
print urlobj.readlines()

1 Like