2013-02-23 39 views
2

我試圖通過URL來在文件命名空間的頁面下載來自於維基共享圖像:wget wikimedia圖片?

wget http://commons.wikimedia.org/wiki/File:A_golden_tree_during_the_golden_season.JPG 

我得到的是一個JPG文件,該文件無法打開。但是,當你去鏈接你實際上看到的頁面,而不是圖像本身,但有一個名爲「全分辨率」的鏈接,將您發送到的實際圖像鏈接是:http://upload.wikimedia.org/wikipedia/commons/9/92/A_golden_tree_during_the_golden_season.JPG

我該如何下載此文件只有第一個鏈接?

+1

爲什麼[tag:bash]?你將不得不在這裏做一些HTML解析。你有沒有考慮過使用[tag:python],[tag:perl],[tag:clojure] ...? – Johnsyweb 2013-02-23 02:31:32

+0

不擅長那些......:/ – 2013-02-23 02:36:00

+2

@AltinUkshini:好的,學習。用Python做並不難。 – Blender 2013-02-23 02:36:37

回答

0
+2

這似乎是在問題中理解。 – Johnsyweb 2013-02-23 02:26:24

+0

是的,我知道,但我想從第一個鏈接得到它... 我有一個圖像名稱列表,我可以做一個wget鏈接/文件:imagename 但這並不工作bcs我下載的圖像無法打開 – 2013-02-23 02:30:27

+0

問題改變了! – kkaehler 2013-02-26 19:19:23

2

你可以嘗試以下方法:

wget http://commons.wikimedia.org/wiki/File:A_golden_tree_during_the_golden_season.JPG -O output.html; wget $(cat output.html | grep fullMedia | sed 's/\(.*href="\/\/\)\([^ ]*\)\(" class.*\)/\2/g') 

第一wget獲取您指定的鏈接。我瀏覽了幾頁,發現高分辨率圖像在div下,class = fullMedia。它解析圖像的URL,然後獲取該圖像。

PS:如上所述,bash不是一個簡單的方法。你應該看看解析dom樹的東西。

+1

+1:您的研究工作值得您信賴。 – Johnsyweb 2013-02-23 07:19:25

+0

@Johnsyweb非常感謝:-) – jitendra 2013-02-23 07:20:50

+0

index.php的action = view(這裏都是通過重寫規則和MediaWiki默認值隱式使用)的輸出取決於各種因素,並可能隨時發生意外更改。不要依賴那個。或者使用[API](http://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url&titles=File:A_golden_tree_during_the_golden_season.JPG)或者提取沒有命名空間的標題並傳遞給[[Special :重定向]],正如我在下面的回覆中所建議的那樣。 – 2014-06-02 16:10:08

2

提取不帶名稱空間的標題(A_golden_tree_during_the_golden_season.JPG)並將其傳遞到Special:Redirect

wget http://commons.wikimedia.org/wiki/Special:Redirect/file/$(echo 'http://commons.wikimedia.org/wiki/File:A_golden_tree_during_the_golden_season.JPG' | sed 's/.*\/File\:\(.*\)/\1/g')