__init__.py 738 B

1234567891011121314151617181920
  1. import execjs
  2. import os
  3. from common.common import Common
  4. def get_xb(f_url, ua):
  5. js_path = os.path.abspath(os.path.dirname(os.getcwd()))
  6. Common.logger(log_type="recommend", crawler="douyin").info(f"js_path:{js_path}/piaoquan_crawler/douyin/xb.js")
  7. # with open(f'{js_path}/xb.js', 'r', encoding='utf-8') as f:
  8. with open(f'{js_path}/piaoquan_crawler/douyin/xb.js', 'r', encoding='utf-8') as f:
  9. douyin_js = f.read()
  10. params = f_url.split('/?')[1]
  11. # params = urllib.parse.unquote(params)
  12. # params = urllib.parse.unquote(urllib.parse.urlencode(params, safe='='))
  13. ctx = execjs.compile(douyin_js)
  14. for i in range(10):
  15. xb = ctx.call('_0x11bbd8', params, ua)
  16. if xb:
  17. return xb