我正在使用python请求获取HTML页面。
我在用户代理中使用了最新版本的chrome。
,但响应告诉Please update your browser
。
这是我的示例代码。
import requests
url = 'https://www.choicehotels.com/alabama/mobile/quality-inn-hotels/al045/hotel-reviews/4'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 'content-type': 'application/xhtml+xml', 'referer': url}
url_response = s.get(url, headers=headers, timeout=15)
print url_response.text
我在Windows Server中使用Python 2.7。
但是,当我在本地划出相同的代码时,我得到了所需的输出。
Please update your browser
是答案。
您不能使用旧浏览器进行HTTP(Python2.7中的请求可能是旧浏览器(。HTTPS协议中有很多安全问题,因此服务器似乎不允许与不安全的加密和连接标准连接。