I have a base url that I would like to append list values to so that I have a list of URLs to scrape. My list comes from a json file, and looks like:
[{u'url': [u'/location/subfile/file1.htm', u'/location/subfile/file2.htm', u'/location/subfile/file3.htm', u'/location/subfile/file4.htm']}]
My base URL is something like http://example.com/placeforfiles/
What I want, ultimately, is a collection of URLs that have that base URL plus the list values, like so:
http://example.com/placeforfiles/location/subfile/file1.htm
http://example.com/placeforfiles/location/subfile/file2.htm
http://example.com/placeforfiles/location/subfile/file3.htm
http://example.com/placeforfiles/location/subfile/file4.htm
There may be thousands of list values I need to append, so I know I need to loop through them and append them but I haven't found a solution that works. I'm currently trying:
import json
with open ('returned_items.json') as links:
data = json.load(links)
base_url = 'http://example.com/placeforfiles/{}'
for i in data:
url = 'http://example.com/placeforfiles/{}'.format(i)
print url
Which is returning:
http://example.com/placeforfiles/({u'url': [u'/location/subfile/file1.htm', u'/location/subfile/file2.htm', u'/location/subfile/file3.htm', u'/location/subfile/file4.htm']},)