使用curl检索内容时如何设置浏览器语言? [英] How to set browser language when using curl to retrieve contents?

查看:141
本文介绍了使用curl检索内容时如何设置浏览器语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它正在使用php中的curl从外部网站获取内容。我从类似 https://www.flickr.com/ 的网站上获取内容。该网站将以不同的语言为浏览器显示不同的内容(以不同的语言)。我只想获取英语内容。我已经尝试过:

It am using curl in php to get contents from external website. I am getting contents from websites like https://www.flickr.com/. The site will show different content (in different languages) for browsers in different languages. I want to get English content only. I have tried:


  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");


但这是行不通的。而是检索中文内容。有任何建议吗?

But it doesn't work. It retrieve Chinese contents instead. Any advice?

推荐答案

设置 接受语言 请求标头,其中使用 CURLOPT_HTTPHEADER 像这样:

curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept-Language: en']);

这篇关于使用curl检索内容时如何设置浏览器语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆