search_by_fakeID.py 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding:utf-8 -*-
  2. import requests
  3. import json
  4. import re
  5. import random
  6. import time
  7. # 基于登录token来模拟登录,token有效期应该是4 * 24h
  8. def get_token():
  9. cookies = [
  10. {'domain': '.qq.com', 'expiry': 1694488114, 'httpOnly': False, 'name': '_clsk', 'path': '/', 'sameSite': 'Lax',
  11. 'secure': False, 'value': '1ni8qoa|1694401714307|1|1|mp.weixin.qq.com/weheat-agent/payload/record'},
  12. {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': False, 'name': 'mm_lang', 'path': '/',
  13. 'sameSite': 'Lax', 'secure': True, 'value': 'zh_CN'},
  14. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_user', 'path': '/',
  15. 'sameSite': 'Lax', 'secure': True, 'value': 'gh_0d8cf8319a3b'},
  16. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_sid', 'path': '/',
  17. 'sameSite': 'Lax', 'secure': True,
  18. 'value': 'cGVCVnJmUkJSclZ2NjNNaXJRNjAxb2RiUk1VUzZJVFZ2OHZHWVhfNDc2eFZ6UE8wRjNialFPSkpGenZ4YjcxeVRCSUJEN2pUV1psTGR3dEVJb01HaEc3OTk1ZGw3czc0cHNqWXp3NmF4TE9sNWpXVFQ0UGZmYk9pMWMyTkhoRGZhRjhZdTRmMWVsNkRtclBw'},
  19. {'domain': 'mp.weixin.qq.com', 'httpOnly': True, 'name': 'uuid', 'path': '/', 'sameSite': 'Lax', 'secure': True,
  20. 'value': '64a3735c687abefa844b964ee5ee22b3'},
  21. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'data_ticket', 'path': '/',
  22. 'sameSite': 'Lax', 'secure': True,
  23. 'value': 'huLvjc4b9KUUU2y5UDhAGtJMnkHdiHLomACVKu3FNRXQNW+cqWis6hmeiDex+48S'},
  24. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'bizuin', 'path': '/',
  25. 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'},
  26. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'data_bizuin', 'path': '/',
  27. 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'},
  28. {'domain': '.qq.com', 'expiry': 1725937701, 'httpOnly': False, 'name': '_clck', 'path': '/', 'sameSite': 'Lax',
  29. 'secure': False, 'value': '1mms0gn|1|fex|0'},
  30. {'domain': 'mp.weixin.qq.com', 'expiry': 1728961701, 'httpOnly': False, 'name': 'wxuin', 'path': '/',
  31. 'sameSite': 'Lax', 'secure': False, 'value': '94401701746369'},
  32. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'slave_bizuin', 'path': '/',
  33. 'sameSite': 'Lax', 'secure': True, 'value': '3524986952'},
  34. {'domain': 'mp.weixin.qq.com', 'expiry': 1694747312, 'httpOnly': True, 'name': 'rand_info', 'path': '/',
  35. 'sameSite': 'Lax', 'secure': True, 'value': 'CAESIFrcVKCpifIofoD16bix61WlVXwAQWuTA8IiGdhqRfVQ'},
  36. {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': True, 'name': 'xid', 'path': '/',
  37. 'sameSite': 'Lax', 'secure': True, 'value': 'f58a1e442db7bee9404cb07398977db9'},
  38. {'domain': 'mp.weixin.qq.com', 'expiry': 1728961710, 'httpOnly': True, 'name': 'ua_id', 'path': '/',
  39. 'sameSite': 'Lax', 'secure': True, 'value': 'EM3eBSFcF5UwBxuLAAAAAA-FF__vfnjkh_D-s1AK7OA='}]
  40. cookie = {}
  41. for items in cookies:
  42. cookie[items.get("name")] = items.get("value")
  43. url = "https://mp.weixin.qq.com"
  44. response = requests.get(url, cookies=cookie)
  45. token = re.findall(r'token=(\d+)', str(response.url))[0] # 从url中获取token
  46. return token, cookie
  47. def extract_fake_id(fake_id):
  48. token, cookie = get_token()
  49. headers = {
  50. "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",
  51. "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",
  52. "Host": "mp.weixin.qq.com",
  53. }
  54. requestUrl = "https://mp.weixin.qq.com/cgi-bin/appmsg?token=" + token + "&lang=zh_CN&f=json&ajax=1&random=" + str(
  55. random.random()) \
  56. + "&action=list_ex&begin=" + str(0) + "&count=5&query=&fakeid={}&type=9".format(fake_id)
  57. search_response = requests.get(requestUrl, cookies=cookie, headers=headers)
  58. re_text = search_response.json()
  59. if re_text['base_resp']['err_msg'] == "freq control":
  60. # 如果被限制频率,可以等待60分钟,时间可以调整
  61. time.sleep(60 * 60)
  62. re_text = extract_fake_id(fake_info)
  63. return re_text
  64. if __name__ == "__main__":
  65. t, c = get_token()
  66. path = "/Users/luojunhui/cyber/gzh_spider/other_functions/fake_id.json"
  67. with open(path, "r", encoding="utf-8") as f:
  68. fake_id_list = json.loads(f.read())
  69. result_list_path = "result_id.json"
  70. f = open("result.txt", "a+", encoding="utf-8")
  71. for fake_info in fake_id_list[53:100]:
  72. response_obj = extract_fake_id(fake_info)
  73. print(response_obj)
  74. time.sleep(random.randint(20, 30))
  75. f.write(json.dumps(response_obj, ensure_ascii=False) + "\n")
  76. f.close()