Code Monkey home page Code Monkey logo

Comments (4)

noahlias avatar noahlias commented on May 23, 2024

I found another question:
fetch data is working with nodejs but not working as expected in the browser .
image

var myHeaders = new Headers();
myHeaders.append(
  "User-Agent",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.68"
);
myHeaders.append("Cookie", "buvid3=321321312");

var requestOptions = {
  method: "GET",
  headers: myHeaders,
  redirect: "follow",
};

fetch(
  "https://api.bilibili.com/x/space/wbi/acc/info?mid=2132180406",
  requestOptions
)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.log("error", error));

from biliscope.

noahlias avatar noahlias commented on May 23, 2024

oh, I got the answer from stackoverflow ,
add the credentials: 'include' , and it make sense . no need to add header and cookie.
image

just change one line code and it works.

fetch(`${BILIBILI_API_URL}/x/space/wbi/acc/info?mid=${userId}`,{credentials: "include"})

from biliscope.

gaogaotiantian avatar gaogaotiantian commented on May 23, 2024

这个大概率是爬得频率太高被block了一小下,和credential没关系。你后面又work了是因为block的时间过去了……如果和credential有关,那这个API肯定所有的情况下没有credential都有问题。

from biliscope.

noahlias avatar noahlias commented on May 23, 2024

哈哈哈哈 好玄学, 就我刚点开的一个打不开

不过就我观察到的关于这个api 的issue来看 它的返回是-401
{"code":-401,"message":"非法访问"}不是大家所说的-509 {"code":-509,"message":"请求过于频繁,请稍后再试","ttl":1},我从网页能看是因为我当时还有登陆的cookie

为了避免cookie影响, 我重现了一下这个场景,在safari浏览器上,我删除了所有bilibili的cookie
访问id为2的:
image

访问之前的id:
image

另外我在bilibili-API-collect 项目文档里面找到一些关于4011的说明,大部分issue2提到如何解决这个问题都是关于加ua和cookie的方式, 之所以加credential是为了解决cookie共享问题 .

Footnotes

  1. https://socialsisteryi.github.io/bilibili-API-collect/docs/user/space.html#%E6%8A%95%E7%A8%BF

  2. https://github.com/SocialSisterYi/bilibili-API-collect/issues?q=401

from biliscope.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.