mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-22 09:03:54 +08:00
Merge pull request #264 from Jeffrey-deng/main
This commit is contained in:
commit
0b4267714b
11
scraper.py
11
scraper.py
@ -82,6 +82,15 @@ class Scraper:
|
||||
except Exception as e:
|
||||
print('Error in get_url:', e)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def relpath(file):
|
||||
""" Always locate to the correct relative path. """
|
||||
from sys import _getframe
|
||||
from pathlib import Path
|
||||
frame = _getframe(1)
|
||||
curr_file = Path(frame.f_code.co_filename)
|
||||
return str(curr_file.parent.joinpath(file).resolve())
|
||||
|
||||
# 生成X-Bogus签名/Generate X-Bogus signature
|
||||
@staticmethod
|
||||
@ -196,7 +205,7 @@ class Scraper:
|
||||
"""
|
||||
# 调用JavaScript函数
|
||||
query = urllib.parse.urlparse(url).query
|
||||
xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, self.headers['User-Agent'])
|
||||
xbogus = execjs.compile(open(self.relpath('./X-Bogus.js')).read()).call('sign', query, self.headers['User-Agent'])
|
||||
print('生成的X-Bogus签名为: {}'.format(xbogus))
|
||||
new_url = url + "&X-Bogus=" + xbogus
|
||||
return new_url
|
||||
|
Loading…
x
Reference in New Issue
Block a user