我想通過我的腳本訪問以下link並下載出現的圖表。用urllib.urlretrieve()保存圖像
我用的是接受響應here實現它,但是當我嘗試打開該文件時,我得到錯誤:The file 「test.png」 could not be opened because it is empty.
這裏是我的代碼片段:
import urllib
image_element = driver.find_element_by_id('chartImg')
src = image_element.get_attribute("src")
if src:
urllib.urlretrieve(str(src), "test.png")
接下來,我想進一步調試並改變了我的代碼
if src:
a, b = urllib.urlretrieve(str(src), "test.png")
print a, b.items()
這給了我下面的輸出:
test.png
[('date', 'Sat, 19 Nov 2016 01:19:20 GMT'), ('connection', 'Keep-Alive'), ('content-length', '0'), ('server', 'BigIP')]
有誰知道爲什麼'content-length'是'0'?我認爲這是下載文件爲空的原因。
感謝,我同意,它將與任何圖像工作擴展名(* .png,* .jpeg),但在這種情況下,由於圖像沒有擴展名,我正在尋找任何可能的提示 – user1596115