我正在尝试搜索Google的某些产品,但Google返回的结果语言取决于代理,因此我尝试使用标题中的’accept-language’:’en-US,en; q = 0.9’来修复它但还是没用
import requests
from bs4 import BeautifulSoup
products=["Majestic Pet Stairs Steps","Ball Jars Wide Mouth Lids 12/Pack","LED Duck Color Changing Floating Speaker"]
for product in products:
headers = {
'authority': 'www.google.com','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/73.0.3683.103 Safari/537.36','accept-language': 'en-US,en;q=0.9'}
url = 'https://google.com/search?q={}'.format(product)
PROXY = None
res=requests.get(url,headers=headers,proxies=PROXY)
if res.status_code!=200:
print("bad proxy")
break
soup = BeautifulSoup(res.text,"lxml")
print(soup.title.text)
我想要的是始终以英语获取结果(无论代理如何)
最佳答案