爬虫相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

90 lines
3.2 KiB

import time
from urllib.parse import urlparse
import requests
import execjs
eval_js = execjs.compile(open('main.js', 'r', encoding='utf-8').read())
def get_a1():
a1 = eval_js.eval('generateLocalId()')
return a1
def get_x_s(url, data=None):
u = urlparse(url)
result = u.path + "?" + u.query
if data:
x_s = eval_js.call('xhs_x_s', result, data)
else:
x_s = eval_js.call('xhs_x_s', result)
return x_s
def get_common(a1, b1):
x_s = eval_js.call('get_common', a1, b1)
return x_s
def get_x_t():
return str(int(time.time() * 1000))
def get_headers(cookie, url):
headers = {
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9",
"authorization;": "",
"cache-control": "no-cache",
"pragma": "no-cache",
"priority": "u=1, i",
"referer": "https://creator.xiaohongshu.com/publish/publish?source=official&from=tab_switch",
"sec-ch-ua": "\"Chromium\";v=\"9\", \"Not?A_Brand\";v=\"8\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 SLBrowser/9.0.6.8151 SLBChan/10 SLBVPV/64-bit",
"x-s": get_x_s(url),
"x-s-common": get_common(cookie['a1'], ''),
"x-t": get_x_t(),
}
return headers
cookies = {
"a1": get_a1(),
"webId": "f2675311fd5ef2666e15073ef7876bb9",
"gid": "yjWf8S8JKJ7qyjWf8S8JJW6j2fJ0xSVhJ6fYvW61Y1A09828yWy69U888yy2jKY8YY0Yjf0i",
"x-user-id-ark.xiaohongshu.com": "6861bde9000000001e01790f",
"customerClientId": "706990196683713",
"x-user-id-fuwu.xiaohongshu.com": "6861bde9000000001e01790f",
"abRequestId": "f2675311fd5ef2666e15073ef7876bb9",
"web_session": "040069769f151fb684b60b65903b4b342673dc",
"id_token": "VjEAAApbUkDez1irEIDK8Xskk9WfmyF6jSocgzGzSSzuhxM1cdthEiup4YdxvB5E6aGLqvdW7DvcwGDBYIbfs0G2mejs1Wf5kYkdDCpD2bFo46Gu3EprnI8se/nm/lE80TPlBClU",
"customer-sso-sid": "68c517612540944882532354dbfxgoivhkkgdhc5",
"x-user-id-creator.xiaohongshu.com": "5a0457e4db2e6045e3f6d4e0",
"access-token-creator.xiaohongshu.com": "customer.creator.AT-68c517612540944882532355njwip1rjvzxfmmyi",
"galaxy_creator_session_id": "hMLkZfiS1vCMl6Ls1unn7AdCJN1EQuNkVHCZ",
"galaxy.creator.beaker.session.id": "1772432808364005045757",
"webBuild": "5.14.0",
"unread": "{%22ub%22:%2269a568c4000000001b01d337%22%2C%22ue%22:%22699edff00000000028008ccc%22%2C%22uc%22:25}",
"acw_tc": "0a0d096b17728479400813507e65716b1f67026c1556a667d2cbd8eef79b3a",
"xsecappid": "ugc",
"loadts": "1772847946657",
"websectiga": "9730ffafd96f2d09dc024760e253af6ab1feb0002827740b95a255ddf6847fc8",
"sec_poison_id": "e52f4379-6e82-42d0-8133-d806bcc4d280"
}
url = 'https://creator.xiaohongshu.com/api/media/v1/upload/creator/permit?biz_name=spectrum&scene=image&file_count=1&version=1&source=web'
response = requests.get(url, headers=get_headers(cookie=cookies,url=url), cookies=cookies)
print(response.text)
print(response)