utils.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2025-04-09
  4. ---------
  5. @summary: 工具
  6. ---------
  7. @author: Dzr
  8. """
  9. import json
  10. import random
  11. import time
  12. import execjs
  13. import requests
  14. def execjs_call(function, param):
  15. with open('./nmgzbtbggfwpt_js.js', 'r') as f:
  16. ex_js = f.read()
  17. ctx = execjs.compile(ex_js)
  18. return ctx.call(function, param)
  19. def fetch_data(sid, tender_id, tender_type, tsqymc=None, proxies=None):
  20. url = "https://www.nmgztb.com.cn/ih5/player/function/run?nid=11057637"
  21. headers = {
  22. "authority": "www.nmgztb.com.cn",
  23. "accept": "*/*",
  24. "accept-language": "zh-CN,zh;q=0.9",
  25. "cache-control": "no-cache",
  26. "content-type": "text/plain;charset=UTF-8",
  27. "origin": "https://www.nmgztb.com.cn",
  28. "referer": "https://www.nmgztb.com.cn/?c=article&a=type&tid=3",
  29. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
  30. }
  31. data_org = {
  32. "TenderId": tender_id,
  33. "TenderType": tender_type,
  34. "_nid": 11057637,
  35. "_uid": 10124717,
  36. "_gid": 17363,
  37. "_eid": 0,
  38. "_sid": sid,
  39. "_locOffset": 28800,
  40. "_lang": "zh"
  41. }
  42. if tsqymc is not None:
  43. data_org["tsqymc"] = tsqymc
  44. data = execjs_call('get_temp', data_org)
  45. res = requests.post(url, headers=headers, data=data, timeout=120, proxies=proxies)
  46. time.sleep(random.randint(3, 5))
  47. json_str = execjs_call('de_data', res.content.decode())
  48. return json.loads(json_str).get('data')