download_qq_tar.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/08/13 12:23:44
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : Download QQ email attachments
  8. Use Chrome to get the download link, replace the cookie to download
  9. '''
  10. import re
  11. import requests
  12. from tqdm import tqdm
  13. import os,sys
  14. if len(sys.argv) != 3:
  15. print("Usage: python script.py <url> <cookie>")
  16. sys.exit(1)
  17. # url =r"""
  18. # cookie =r""
  19. url = sys.argv[1]
  20. cookie = sys.argv[2]
  21. headers = {
  22. 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
  23. "cookie": cookie
  24. }
  25. def run():
  26. """ run """
  27. response = requests.get(url, headers=headers, stream=True)
  28. total_size = int(response.headers.get('content-length', 0))
  29. with open("result.zip", "wb") as file:
  30. with tqdm(total=total_size, unit='B', unit_scale=True, unit_divisor=1024) as bar:
  31. for chunk in response.iter_content(chunk_size=1024):
  32. if chunk:
  33. file.write(chunk)
  34. bar.update(len(chunk))
  35. if __name__=='__main__':
  36. run()