首页 > 解决方案 > 阻止 Google 自动更改结果语言

问题描述

我正在尝试使用以下代码从 NodeJS 进行谷歌搜索,并尝试将其发送到 whatsapp 机器人,但这无关紧要。我使用的查询字符串是https://google.com/search?hl=en&q=我将语言设置为英语的地方,hl=en但由于我的服务器在德国,所以我得到的是德语的结果。有什么办法可以防止它并以英语获得结果吗?

let handler = async (m, { conn, command, args }) => {
  let full = /f$/i.test(command)
  let text = args.join` `
  if (!text) return conn.reply(m.chat, 'There is no text to search', m)
  let url = 'https://google.com/search?hl=en&q=' + encodeURIComponent(text)
  let search = await googleIt({ query: text })
  let msg = search.map(({ title, link, snippet }) => {
    return `${title}\n_${link}\n${snippet}_`
  }).join`\n\n`

   m.reply(msg) 
}

标签: node.jsgoogle-search-api

解决方案


推荐阅读