Skip to content

Instantly share code, notes, and snippets.

@27Cobalter
Created November 5, 2019 13:44
Show Gist options
  • Save 27Cobalter/d61031a364cdac96afa1a247c3736d76 to your computer and use it in GitHub Desktop.
Save 27Cobalter/d61031a364cdac96afa1a247c3736d76 to your computer and use it in GitHub Desktop.
ディレクトリのlist.txtにかかれているURLのパラメータをpngのlargeにしてダウンロードするスクリプト
# pip install requests
import requests
import urllib.parse
if __name__ == "__main__":
with open("list.txt") as f:
lines=f.readlines()
for i in range(len(lines)):
pr=urllib.parse.urlparse(lines[i])
qs=urllib.parse.parse_qs(pr.query)
qs['format']='png'
qs['name']='large'
url=urllib.parse.urlunparse(pr._replace(query=urllib.parse.urlencode(qs)))
print(url)
response=requests.get(url)
image=response.content
with open("pic/"+str(i)+".png",'wb') as wf:
wf.write(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment