我试图使用urllib.urlretrieve来抓取this image。用urlretrieve将图片作为HTML页面抓取
>>> import urllib
>>> urllib.urlretrieve('http://i9.mangareader.net/one-piece/3/one-piece-1668214.jpg',
path) # path was previously defined
此代码成功地将文件保存在给定路径中。然而,当我尝试打开该文件,我得到:
Could not load image 'imagename.jpg':
Error interpreting JPEG image file (Not a JPEG file: starts with 0x3c 0x21)
当我在我的bash终端做file imagename.jpg
,我得到imagefile.jpg: HTML document, ASCII text
。
那么如何将这张图像作为JPEG文件进行刮取?
顺便说一下'request'没有问题:http://stackoverflow.com/questions/16694907/how-to-download-large-file-in-python-with-requests-py。 – alecxe
谢谢,我会给它一个镜头。不知道为什么这不起作用,但?我做错了什么,或者我误解了urlretrieve的工作原理? – NJay
谢谢,请求完美。 :) – NJay