test.py 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding:utf-8 -*-
  2. import requests
  3. import json
  4. import re
  5. import random
  6. import time
  7. def get_token():
  8. cookies = [{'domain': '.qq.com', 'expiry': 1694488114, 'httpOnly': False, 'name': '_clsk', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1ni8qoa|1694401714307|1|1|mp.weixin.qq.com/weheat-agent/payload/record'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': False, 'name': 'mm_lang', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'zh_CN'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_user', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'gh_0d8cf8319a3b'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_sid', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'cGVCVnJmUkJSclZ2NjNNaXJRNjAxb2RiUk1VUzZJVFZ2OHZHWVhfNDc2eFZ6UE8wRjNialFPSkpGenZ4YjcxeVRCSUJEN2pUV1psTGR3dEVJb01HaEc3OTk1ZGw3czc0cHNqWXp3NmF4TE9sNWpXVFQ0UGZmYk9pMWMyTkhoRGZhRjhZdTRmMWVsNkRtclBw'}, {'domain': 'mp.weixin.qq.com', 'httpOnly': True, 'name': 'uuid', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': '64a3735c687abefa844b964ee5ee22b3'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'data_ticket', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'huLvjc4b9KUUU2y5UDhAGtJMnkHdiHLomACVKu3FNRXQNW+cqWis6hmeiDex+48S'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'bizuin', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'data_bizuin', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'}, {'domain': '.qq.com', 'expiry': 1725937701, 'httpOnly': False, 'name': '_clck', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1mms0gn|1|fex|0'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1728961701, 'httpOnly': False, 'name': 'wxuin', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '94401701746369'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_bizuin', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'rand_info', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'CAESIFrcVKCpifIofoD16bix61WlVXwAQWuTA8IiGdhqRfVQ'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': True, 'name': 'xid', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'f58a1e442db7bee9404cb07398977db9'}, {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': True, 'name': 'ua_id', 'path': '/', 'sameSite': 'Lax', 'secure': True, 'value': 'EM3eBSFcF5UwBxuLAAAAAA-FF__vfnjkh_D-s1AK7OA='}]
  9. cookie = {}
  10. for items in cookies:
  11. cookie[items.get("name")] = items.get("value")
  12. url = "https://mp.weixin.qq.com"
  13. response = requests.get(url, cookies=cookie)
  14. print(response.url)
  15. token = re.findall(r'token=(\d+)', str(response.url))[0] # 从url中获取token
  16. return token, cookie
  17. def extract_fake_id(fake_id):
  18. token, cookie = get_token()
  19. headers = {
  20. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
  21. "Referer": "https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit_v2&action=edit&isNew=1&type=10&token=" + token + "&lang=zh_CN",
  22. "Host": "mp.weixin.qq.com",
  23. }
  24. requestUrl = "https://mp.weixin.qq.com/cgi-bin/appmsg?token=" + token + "&lang=zh_CN&f=json&ajax=1&random=" + str(
  25. random.random()) \
  26. + "&action=list_ex&begin=" + str(0) + "&count=5&query=&fakeid={}&type=9".format(fake_id)
  27. search_response = requests.get(requestUrl, cookies=cookie, headers=headers)
  28. re_text = search_response.json()
  29. return re_text
  30. if __name__ == "__main__":
  31. t, c = get_token()
  32. path = "/Users/luojunhui/cyber/gzh_spider/other_functions/fake_id.json"
  33. with open(path, "r", encoding="utf-8") as f:
  34. fake_id_list = json.loads(f.read())
  35. result_list_path = "result_id.json"
  36. f = open("result.txt", "a+", encoding="utf-8")
  37. for fake_info in fake_id_list[53:100]:
  38. response_obj = extract_fake_id(fake_info)
  39. print(response_obj)
  40. time.sleep(random.randint(20, 30))
  41. f.write(json.dumps(response_obj, ensure_ascii=False) + "\n")
  42. f.close()
  43. # if os.path.exists(result_list_path):
  44. # with open(result_list_path, "r", encoding="utf-8") as f:
  45. # result_list = json.loads(f.read())
  46. # result_list.append(response_obj)
  47. # else:
  48. # result_list = [response_obj]
  49. #
  50. # # 写文件
  51. # with open(result_list_path, "w", encoding="utf-8") as f: