Javascript Python请求响应不同于chrome响应
我需要从一个特定的网站下载大约100个验证码图像。 我的代码总结如下: 1-下载页面 2-搜索验证码图像URL(使用re)并下载 3-:(下载的图像与我在浏览器中看到的不同。我猜会话或请求(get或post)中有一个参数需要设置,但我没有设置Javascript Python请求响应不同于chrome响应,javascript,python,http,captcha,Javascript,Python,Http,Captcha,我需要从一个特定的网站下载大约100个验证码图像。 我的代码总结如下: 1-下载页面 2-搜索验证码图像URL(使用re)并下载 3-:(下载的图像与我在浏览器中看到的不同。我猜会话或请求(get或post)中有一个参数需要设置,但我没有设置 import requests import re import time s = requests.Session() headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10
import requests
import re
import time
s = requests.Session()
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
#download this page and look for the url of the captcha image
page = s.get('http://www.rrk.ir/News/ShowOldNews.aspx?Code=1', headers=headers)
result = re.search('img id="imgCaptcha" src="..(.*)"', page.content.decode('utf-8'))
img_url = 'http://www.rrk.ir' + result.group(1).split('"')[0]
print(img_url)
#download the image and save it to a file
img = s.get(img_url, headers=headers)
img_file_name = './a' + '.jpg'
with open(img_file_name, 'wb') as fout:
fout.write(img.content)
s.close()
#:( the downloaded file is different from what I see in Chrome.
我怎样才能知道我错过了什么设置
更新1:根据建议,添加了自定义标题,但没有帮助。发送类似浏览器的标题。从用户代理开始。因为这样,服务器肯定能够知道它是Python脚本。链接到自定义标题部分文档-添加了用户代理,没有帮助:(