create_cookies.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2021/4/25 10:22 上午
  4. ---------
  5. @summary: 将浏览器的cookie转为request的cookie
  6. ---------
  7. @author: Boris
  8. @email: boris_liu@foxmail.com
  9. """
  10. import json
  11. import sys
  12. from feapder.utils.tools import get_cookies_from_str, print_pretty
  13. class CreateCookies:
  14. def get_data(self):
  15. """
  16. @summary: 从控制台读取多行
  17. ---------
  18. ---------
  19. @result:
  20. """
  21. print("请输入浏览器cookie (列表或字符串格式)")
  22. data = []
  23. while True:
  24. line = sys.stdin.readline().strip()
  25. if not line:
  26. break
  27. data.append(line)
  28. return "".join(data)
  29. def create(self):
  30. data = self.get_data()
  31. cookies = {}
  32. try:
  33. data_json = json.loads(data)
  34. for data in data_json:
  35. cookies[data.get("name")] = data.get("value")
  36. except:
  37. cookies = get_cookies_from_str(data)
  38. print_pretty(cookies)