gpt4 book ai didi

python - 我有一个包含 urls-pdf 的列表,我想将它们本地保存到我的电脑上

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:27 27 4
gpt4 key购买 nike

我是 python 新手,所以我有特定的 json 并且我已经提取了从字典中获取 documentElement 值,然后将其制成列表...如何自动将此 pdf 下载到目录文件夹?

import urllib.request
import requests
import json

url = 'https://diavgeia.gov.gr/luminapi/api/search/export?q=decisionType:%22%CE%93%CE%9D%CE%A9%CE%9C%CE%9F%CE%94%CE%9F%CE%A4%CE%97%CE%A3%CE%97%22&OrganizationUid:%2250024%22&status:%22%CE%91%CE%BD%CE%B1%CF%81%CF%84%CE%B7%CE%BC%CE%AD%CE%BD%CE%B7%22&page=1&size=4&wt=json'


#get urls
response = requests.get(url)
with urllib.request.urlopen(url) as u:
data = json.loads(u.read().decode())
#add links to the list
pdf_links = list()
for key in data:
for x in data[key]:
pdf_links.append(x['documentUrl'])
#print
print(pdf_links)

最佳答案

我们开始:

import requests
response = requests.get('https://diavgeia.gov.gr/luminapi/api/search/export?q=decisionType:%22%CE%93%CE%9D%CE%A9%CE%9C%CE%9F%CE%94%CE%9F%CE%A4%CE%97%CE%A3%CE%97%22&OrganizationUid:%2250024%22&status:%22%CE%91%CE%BD%CE%B1%CF%81%CF%84%CE%B7%CE%BC%CE%AD%CE%BD%CE%B7%22&page=1&size=4&wt=json')
for doc in response.json()['decisionResultList']:
r = requests.get(doc['documentUrl'], stream=True)
with open('{}.pdf'.format(doc['ada']), 'wb') as f:
for chunk in r:
f.write(chunk)

以下文件已下载到我的电脑:

enter image description here

关于python - 我有一个包含 urls-pdf 的列表,我想将它们本地保存到我的电脑上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54422013/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com