【发布时间】:2016-11-16 17:25:15
【问题描述】:
我正在尝试使用 urllib.urlretrieve 抓取 this image。
>>> 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 文件呢?
【问题讨论】:
-
requests没有问题,顺便说一句:stackoverflow.com/questions/16694907/…。 -
谢谢,我会试一试。知道为什么这不起作用吗?是我做错了什么,还是我误解了 urlretrieve 的工作原理?
-
谢谢,请求完美运行。 :)
标签: python web-scraping urllib