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

Bing Web API v7如何获取仅英文结果?已尝试setLang等方法无效

How to Filter Bing Web API v7 Results to English Only (Without Reducing Result Count)

I’ve run into this exact issue before—setLang and Accept-Language alone don’t always cut it for strict English-only content filtering. Here’s what actually works, prioritizing server-side solutions first:

1. Use the mkt Parameter (Server-Side, Most Effective)

The setLang parameter mainly controls the language of the API’s response metadata (like error messages), not the content language of the search results. Instead, use the mkt (market) parameter to target a specific English-speaking region. This tells Bing to prioritize content from that market, which is nearly always English.

For example, use:

  • mkt=en-US (English, United States)
  • mkt=en-GB (English, United Kingdom)
  • mkt=en-AU (English, Australia)

Combine this with setLang=en and the Accept-Language header to reinforce your request:

curl -H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
     -H "Accept-Language: en-US" \
     "https://api.bing.microsoft.com/v7.0/websearch?q=your-search-query&mkt=en-US&setLang=en&count=10"

2. Add the cc Parameter (Optional, Extra Narrowing)

If you still see occasional non-English results, pair mkt with the cc (country code) parameter to restrict results to content hosted in an English-speaking country. For example:
cc=US (United States) or cc=GB (United Kingdom)

This adds another layer of server-side filtering to ensure content is tied to an English-speaking region.

3. Fallback to Client-Side Filtering (Preserve Result Count)

If server-side filtering still returns a few non-English entries (rare, but possible for broad queries), adjust the count parameter to request more results than you need. For example, if you need 10 English results, request 15. Then, filter the response’s webPages.value array client-side to select only entries where language equals "en" until you have your desired number of results.

Here’s a quick JavaScript example of this fallback:

const desiredCount = 10;
const rawResults = response.webPages.value;
const englishResults = rawResults.filter(item => item.language === "en").slice(0, desiredCount);

4. Double-Check Your Endpoint

Ensure you’re using the correct v7 web search endpoint: https://api.bing.microsoft.com/v7.0/websearch. Using a different endpoint (like the general search endpoint) might not respect all filtering parameters as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:59:39