Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token的获取 #1

Open
zp0605 opened this issue Nov 19, 2018 · 4 comments
Open

token的获取 #1

zp0605 opened this issue Nov 19, 2018 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@zp0605
Copy link

zp0605 commented Nov 19, 2018

获取token的时候,能不能考虑用程序去自动获取;

@uname-yang uname-yang added the help wanted Extra attention is needed label Dec 4, 2018
@uname-yang
Copy link
Owner

手机验证码不太好处理

@refraction-ray
Copy link

@uname-yang ,匿名用户好像也可以拿到 token 和访问股票数据 API

import requests
r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla"})
print(r.cookies["xq_a_token"])

这样就可以了,该 token 能拿到股票日线数据,别的 API 我没测试。

而且其实我发现,不管什么 UA 和什么 ip,只要未登录(也就是运行上面的代码),拿到的这个 token 似乎是一样的。。。
都是“a664afb60c7036c7947578ac1a5860c4cfb6b3b5”。不知道这个是随比较大的时间范围会变还是根本就不变,反正这个 token 作为唯一 cookie 是能成功拿到雪球日线数据的。仅供参考。

测试 demo:

import requests
r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla"})
t = r.cookies["xq_a_token"]
data = requests.get("https://stock.xueqiu.com/v5/stock/chart/kline.json\
?symbol=SH600000&begin=1583552766531&period=day&type=before&count=-142", cookies={"xq_a_token": t},  headers={"user-agent":"Mozilla/5.0"})
print(data.json())

@uname-yang
Copy link
Owner

@uname-yang ,匿名用户好像也可以拿到 token 和访问股票数据 API

import requests
r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla"})
print(r.cookies["xq_a_token"])

这样就可以了,该 token 能拿到股票日线数据,别的 API 我没测试。

而且其实我发现,不管什么 UA 和什么 ip,只要未登录(也就是运行上面的代码),拿到的这个 token 似乎是一样的。。。 都是“a664afb60c7036c7947578ac1a5860c4cfb6b3b5”。不知道这个是随比较大的时间范围会变还是根本就不变,反正这个 token 作为唯一 cookie 是能成功拿到雪球日线数据的。仅供参考。

测试 demo:

import requests
r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla"})
t = r.cookies["xq_a_token"]
data = requests.get("https://stock.xueqiu.com/v5/stock/chart/kline.json\
?symbol=SH600000&begin=1583552766531&period=day&type=before&count=-142", cookies={"xq_a_token": t},  headers={"user-agent":"Mozilla/5.0"})
print(data.json())

有几个api 是不用加token就能访问的,大部分还是需要加的。这个token只要不超限速被过期,正常的过期时间是一个月。

@xuzhishen
Copy link

雪球又升级了, 现在是先给一个acw_tc,然后拿acw_tc 和 acw_sc__v2 换一个token.

import requests

r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla"})
acw_tc = r.cookies["acw_tc"]
print(acw_tc)
r = requests.get("https://xueqiu.com", headers={"user-agent":"Mozilla" }, cookies={"acw_tc":acw_tc, "acw_sc__v2":"670ce5a06513aa53a445eed2989cdace85d6fb3a"})
print(r.cookies["xq_a_token"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants