Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Python请求响应不同于chrome响应_Javascript_Python_Http_Captcha - Fatal编程技术网

Javascript Python请求响应不同于chrome响应

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

我需要从一个特定的网站下载大约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_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脚本。链接到自定义标题部分文档-添加了用户代理,没有帮助:(