download.py 835 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. import requests # http客户端
  4. import os # 创建文件夹
  5. import time
  6. from PIL import Image
  7. os.makedirs('./image/', exist_ok=True)
  8. IMAGE_URL = "https://app.yunnan.chinatax.gov.cn/app/base/captcha.do?time=" + (str(round(time.time() * 1000)))
  9. print(IMAGE_URL)
  10. head = {
  11. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
  12. }
  13. def request_download(num):
  14. r = requests.get(IMAGE_URL, headers=head)
  15. with open('./image/%s.png' % str(num), 'wb') as f:
  16. f.write(r.content)
  17. try:
  18. for i in range(100):
  19. request_download((i+1))
  20. print('download to ./image/%s.png' % str((i+1)))
  21. #im = Image.open('./image/img.png')
  22. #im.show()
  23. except:
  24. print('download error!')