Answer the question
In order to leave comments, you need to log in
How to extract all links to python from json?
Here is an excerpt from the json file:
"editions":[{"title":"\u0423\u0447\u0435\u0431\u043d\u0438\u043a","description":null,"type":"1","publisher_id":"31","texts":[],"images":[{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5be55bf80f89d.jpg"},{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5be55bf80fca3.jpg"}],"documents":[]},{"title":"\u0420\u0435\u0448\u0435\u0431\u043d\u0438\u043a","description":null,"type":"2","publisher_id":"2","texts":[],"images":[{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5ba0f2d96dc89.jpg"},{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5ba0f2d96e060.jpg"},{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5ba0f2d96e5e4.jpg"},{"title":null,"url":"\/attachments\/images\/tasks\/000\/096\/125\/0002\/5ba0f2d96eaa3.jpg"}
def get_url_for_img(url):
s=requests.get(url)
data = s.json()
k = []
k = data['editions'][0]['images'][0]['url']
return k#/attachments/images/tasks/000/096/125/0002/5be55bf80f89d.jpg
Answer the question
In order to leave comments, you need to log in
def get_url_for_img(url):
data = requests.get(url).json()
for edition in data['editions']:
for image in edition['images']:
yield image['url']
def get_url_for_img(url):
data = requests.get(url).json()
result = []
for edition in data['editions']:
for image in edition['images']:
result.append(image['url'])
return result
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question