You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用node-fetch向Bing发送Cookie以获取每页50条搜索结果?

Bing搜索每页显示50条结果的正确实现方法

一、修复Cookie格式错误

你当前的Cookie写法有误,SRCHHPGUSR是Bing存储搜索偏好的Cookie键,它的值需要包含NRSLT=50这个参数,而非把SRCHHPGUSR和NRSLT=50分开写。正确的Cookie格式示例:

SRCHHPGUSR=ADLT=OFF&NRSLT=50&SRCHLANG=zh-CN; [其他必要会话Cookie]

修正后的基础代码:

const opts = {
    headers: {
        "cookie": "SRCHHPGUSR=ADLT=OFF&NRSLT=50&SRCHLANG=zh-CN; SRCHUID=XXX; SRCHUSR=XXX",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
    },
};
const response = await fetch("https://www.bing.com/search?q=example", opts);

二、补充会话Cookie(关键)

仅传SRCHHPGUSR大概率不生效,因为Bing会验证会话相关Cookie(如SRCHUID、SRCHUSR)。需先向Bing首页发送请求获取初始会话Cookie,再拼接偏好Cookie:

// 1. 获取初始会话Cookie
const initResponse = await fetch("https://www.bing.com/");
const initCookies = initResponse.headers.get("set-cookie");

// 2. 提取必要会话Cookie并拼接偏好设置
const sessionCookies = initCookies.split('; ')
    .filter(c => c.startsWith('SRCHUID=') || c.startsWith('SRCHUSR='))
    .join('; ');
const targetCookies = `${sessionCookies}; SRCHHPGUSR=ADLT=OFF&NRSLT=50&SRCHLANG=zh-CN`;

// 3. 发送搜索请求
const searchOpts = {
    headers: {
        "cookie": targetCookies,
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
    },
};
const searchResponse = await fetch("https://www.bing.com/search?q=example", searchOpts);
const html = await searchResponse.text();
// 此时返回的html应包含50条搜索结果

三、其他注意事项

  • 必须添加User-Agent头模拟浏览器请求,否则Bing会拒绝返回正常结果
  • 频繁请求可能触发Bing反爬机制,需控制请求间隔,必要时使用代理
  • 部分地区的Bing对count参数有限制,Cookie偏好设置是更稳定的实现方式

内容的提问来源于stack exchange,提问作者guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 19:06:26