Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
使用Python mechanize保存随机生成的图片_Python_Image_Mechanize - Fatal编程技术网

使用Python mechanize保存随机生成的图片

使用Python mechanize保存随机生成的图片,python,image,mechanize,Python,Image,Mechanize,我想从web上保存一张在每次请求时随机生成的图片,我尝试使用.retrieve()获取它,但它不起作用(它会下载另一张随机图片) 如果有必要,我不介意下载整个页面 import urllib2 referer = 'link of the page of image' image = 'image link ' req = urllib2.Request(image) req.add_header('Referer', referer) # here is the trick resp

我想从web上保存一张在每次请求时随机生成的图片,我尝试使用.retrieve()获取它,但它不起作用(它会下载另一张随机图片)

如果有必要,我不介意下载整个页面

import urllib2
referer = 'link of the page of image'
image   = 'image link '

req = urllib2.Request(image)
req.add_header('Referer', referer)   # here is the trick
response = urllib2.urlopen(req)

output = open('out.jpg','wb')
output.write(response.read())
output.close()

这就是你问题的解决办法

显示您的代码。如果图像始终具有相同的名称/路径,则可以使用
curl
代替python。