我在我的网站http://shedez.com/test.html上创建了一个页面, 此页面将用户重定向到我服务器上的 jpg
我想使用 python 脚本将此图像复制到我的本地驱动器。我希望python脚本先转到主网址,然后再转到图片的目标网址
而不是复制图像。到目前为止,目标 url 是硬编码的,但将来它将是动态的,因为我将使用地理编码通过 ip 查找城市,然后将我的用户从他们的城市重定向到当天的图片。
==我现在的剧本===
import urllib2, os
req = urllib2.urlopen("http://shedez.com/test.html")
final_link = req.info()
print req.info()
def get_image(remote, local):
imgData = urllib2.urlopen(final_link).read()
output = open(local,'wb')
output.write(imgData)
output.close()
return local
fn = os.path.join(self.tmp, 'bells.jpg')
firstimg = get_image(final_link, fn)