参考:
知乎
LLI ,ibra146
会修电脑的程序猿
scrapy学习之爬虫练习平台2
B站
https://www.bilibili.com/video/BV1Mf4y1s7ds?p=42
主要就是破解这个token值
思路分析:
1:当下时间戳time.time()取整,得t,假设t为1625572736
2:["/api/movie", 0, “1625572736”]----》/api/movie,0,1625572736
将 /api/movie,0,1625572736 用SHA1加密,化为16进制编码字符串,这字符串就是o的value
o = “d1983455197bf53903c2a2f6cf57a9a53863b923”
3: 将o与t用英文逗号连接,用Base64加密,即加密
d1983455197bf53903c2a2f6cf57a9a53863b923,1625572736
得出68位非人类看懂的字符串,也就浏览器看得爽
ZDE5ODM0NTUxOTdiZjUzOTAzYzJhMmY2Y2Y1N2E5YTUzODYzYjkyMywxNjI1NTcyNzM2
这就是token值
#4:得出的token值是二进制,要将其转为通用字符串
import requests
import time
import hashlib
import base64
def getHTMLText(url):
try:
r=requests.get(url,timeout=60)
r.raise_for_status()
r.encoding='utf-8'
return r.json()
except:
pass
#1:时间戳取整
t=int(time.time())
#2:SHA1加密
s1 = f"/api/movie,0,{
t}"
o = hashlib.sha1(s1.encode("utf-8")).hexdigest()
s2=f'{
o},{
t}'
s3=s2.encode('utf-8')
#3:Base64加密
token=base64.b64encode(s3)
#4:bytes转str
token=token.decode()
print(token)
url=f"https://spa2.scrape.center/api/movie/?limit=10&offset=0&token={
token}"
html=getHTMLText(url)
print(html)
for i in range(10):
print(html['results'][i]['id'],html['results'][i]['name'])
以上是第一页列表,以下是第二页列表,原来这个红线指的参数不是固定的,是根据offset的变化而变化
import time
import requests
def