吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1348|回复: 9
收起左侧

[已解决] 一个简单的请求python成功了但js axios却拿不到数据,这是为什么

  [复制链接]
柒呀柒 发表于 2021-2-13 09:44
本帖最后由 柒呀柒 于 2021-2-13 13:06 编辑

[Python] 纯文本查看 复制代码
import requests

url = 'https://sports.weibo.cn/aj/rank/votenum?'

headers = {
    "Accept": "application/json",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9,zh-TW;q=0.8",
    "Connection": "keep-alive",
    "Content-Length": "109",
    "Content-Type": "application/x-www-form-urlencoded",
    "Cookie":
    "SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWaEIUm4Idu-qxB.Uo2v6-i5NHD95QcSK2cS0qcSKefWs4DqcjTHsvF9-4DMr9ydJ2t; SUB=_2A25NIU_8DeRhGeBL6lQW9ijJyDmIHXVu6lG0rDV6PUJbktAKLUXGkW1NR1c_bURfKz_pl_s4_HD8n6qFx6rFwYYZ; I-SASS-YF=c2553663d2d9e8f43787d85bedde20eb; WEIBOCN_FROM=1110106030; MLOGIN=1; _T_WM=65779948426; M_WEIBOCN_PARAMS=uicode%3D20000174",
    "DNT": "1",
    "Host": "sports.weibo.cn",
    "Origin": "https://sports.weibo.cn",
    "Referer":
    "https://sports.weibo.cn/rank/index?topicid=pu1m3iNB1qqj&bid=pHNmN33BBgjQ&portrait_only=1&disable_sinaurl=1&sinainternalbrowser=topnav&share_menu=1&disable_gesture_back=1",
    "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/88.0.4324.150 Safari/537.36",
    "X-Requested-With": "XMLHttpRequest"
}

data = {
    "bid": "pHNmN33BBgjQ",
    "tid": "pu1m3iNB1qqj",
    "id": "9023",
    "uid": "6516766535",
    "vid": "9023",
    "securityid": "66a740e0eea7819626b134f69abe29d7"
}

res = requests.post(url, data=data, headers=headers)
print(res.status_code, res.text)


[JavaScript] 纯文本查看 复制代码
const axios = require('axios')


let url = 'https://sports.weibo.cn/aj/rank/votenum?'

let headers = {
  "Accept": "application/json",
  "Accept-Encoding": "gzip, deflate, br",
  "Accept-Language": "zh-CN,zh;q=0.9,zh-TW;q=0.8",
  "Connection": "keep-alive",
  "Content-Length": "109",
  "Content-Type": "application/x-www-form-urlencoded",
  "Cookie":
  "SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWaEIUm4Idu-qxB.Uo2v6-i5NHD95QcSK2cS0qcSKefWs4DqcjTHsvF9-4DMr9ydJ2t; SUB=_2A25NIU_8DeRhGeBL6lQW9ijJyDmIHXVu6lG0rDV6PUJbktAKLUXGkW1NR1c_bURfKz_pl_s4_HD8n6qFx6rFwYYZ; I-SASS-YF=c2553663d2d9e8f43787d85bedde20eb; WEIBOCN_FROM=1110106030; MLOGIN=1; _T_WM=65779948426; M_WEIBOCN_PARAMS=uicode%3D20000174",
  "DNT": "1",
  "Host": "sports.weibo.cn",
  "Origin": "https://sports.weibo.cn",
  "Referer":
  "https://sports.weibo.cn/rank/index?topicid=pu1m3iNB1qqj&bid=pHNmN33BBgjQ&portrait_only=1&disable_sinaurl=1&sinainternalbrowser=topnav&share_menu=1&disable_gesture_back=1",
  "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/88.0.4324.150 Safari/537.36",
  "X-Requested-With": "XMLHttpRequest"
}

let data = {
  bid: "pHNmN33BBgjQ",
  tid: "pu1m3iNB1qqj",
  id: "9023",
  uid: "6516766535",
  vid: "9023",
  securityid: "66a740e0eea7819626b134f69abe29d7"
}

axios({
  method: 'post',
  url,
  headers,
  data: {
    "bid": "pHNmN33BBgjQ",
    "tid": "pu1m3iNB1qqj",
    "id": "9023",
    "uid": "6516766535",
    "vid": "9023",
    "securityid": "66a740e0eea7819626b134f69abe29d7"
  }
}).then(res => {
  console.log(res.data);
})



QQ图片20210213094230.jpg

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
chensweet + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 柒呀柒 发表于 2021-2-13 09:53
有没有小伙伴 告诉我这是为什么
Lasy 发表于 2021-2-13 09:57
 楼主| 柒呀柒 发表于 2021-2-13 10:00
Lasy 发表于 2021-2-13 09:57
运行结果是什么

运行结果 图片有,data里面的数据,axios请求不到
shiory 发表于 2021-2-13 10:03
本帖最后由 shiory 于 2021-2-13 10:04 编辑

axios是在node里面发的么,感觉被认出来了。抓下包看下。
 楼主| 柒呀柒 发表于 2021-2-13 10:29
shiory 发表于 2021-2-13 10:03
axios是在node里面发的么,感觉被认出来了。抓下包看下。

试了下fiddle axios不知道为什么我抓不到, python的直接报错了 提示ssl之类的
狒狒大魔王 发表于 2021-2-13 10:45
将Content-Type改成application/json 试试
linguo2625469 发表于 2021-2-13 11:11
报错了啊
code10001
要么参数没收到 要么请求头问题
成功的是200  你的node是10001
linguo2625469 发表于 2021-2-13 11:16
"Content-Type": "application/x-www-form-urlencoded",
这里设置了用的formdata发送数据
需要你对data处理
[JavaScript] 纯文本查看 复制代码
const axios = require('axios')
 
 
let url = 'https://sports.weibo.cn/aj/rank/votenum?'
 
let headers = {
  "Accept": "application/json",
  "Accept-Encoding": "gzip, deflate, br",
  "Accept-Language": "zh-CN,zh;q=0.9,zh-TW;q=0.8",
  "Connection": "keep-alive",
  "Content-Length": "109",
  "Content-Type": "application/x-www-form-urlencoded",
  "Cookie":
  "SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWaEIUm4Idu-qxB.Uo2v6-i5NHD95QcSK2cS0qcSKefWs4DqcjTHsvF9-4DMr9ydJ2t; SUB=_2A25NIU_8DeRhGeBL6lQW9ijJyDmIHXVu6lG0rDV6PUJbktAKLUXGkW1NR1c_bURfKz_pl_s4_HD8n6qFx6rFwYYZ; I-SASS-YF=c2553663d2d9e8f43787d85bedde20eb; WEIBOCN_FROM=1110106030; MLOGIN=1; _T_WM=65779948426; M_WEIBOCN_PARAMS=uicode%3D20000174",
  "DNT": "1",
  "Host": "sports.weibo.cn",
  "Origin": "https://sports.weibo.cn",
  "Referer":
  "https://sports.weibo.cn/rank/index?topicid=pu1m3iNB1qqj&bid=pHNmN33BBgjQ&portrait_only=1&disable_sinaurl=1&sinainternalbrowser=topnav&share_menu=1&disable_gesture_back=1",
  "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/88.0.4324.150 Safari/537.36",
  "X-Requested-With": "XMLHttpRequest"
}
 
let data = {
  bid: "pHNmN33BBgjQ",
  tid: "pu1m3iNB1qqj",
  id: "9023",
  uid: "6516766535",
  vid: "9023",
  securityid: "66a740e0eea7819626b134f69abe29d7"
}
// data=JSON.stringify(data)
axios({
  method: 'post',
  url,
  headers,
  transformRequest: [
    function (data) {
       let ret = ''
       for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
       }
       ret = ret.substring(0, ret.lastIndexOf('&'));
       return ret
    }
  ],
  data: data
}).then(res => {
  console.log(res.data);
})


或者使用qs模块 将data转为formdata发送
52node.jpg

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
柒呀柒 + 1 + 1 谢谢@Thanks!

查看全部评分

 楼主| 柒呀柒 发表于 2021-2-13 13:04
linguo2625469 发表于 2021-2-13 11:16
"Content-Type": "application/x-www-form-urlencoded",
这里设置了用的formdata发送数据
需要你对data处 ...

谢谢大佬,学到了,学到了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 08:23

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表