Programatically determining the URL of a MediaWiki image

旧城冷巷雨未停 提交于 2019-12-11 02:24:38

问题


I'm trying to download images from specific MediaWiki pages (Or just specific images) using a PHP script.

I can run a query through the api, by retrieving the page at the following URL

.../w/action=query&prop=images&titles=Abakanskiy

and get a response

<?xml version="1.0"?>
<api>
  <query>
    <pages>
      <page pageid="260" ns="0" title="Abakanskiy">
        <images>
          <im ns="6" title="File:Abakanskiy.jpg" />
        </images>
      </page>
    </pages>
  </query>
</api>

So far, so good.

Now, no matter what I've done with the query, I haven't figured out how I can construct, or retrieve the image's actual URL - in this case, it is

.../w/images/3/38/Abakanskiy.jpg

Am I missing something obvious?

I realise that there exists a naive solution - getting the source of the page containing the image, parsing it for the tag, and then getting the image from the specified URL - however, if possible, I'd rather use the API.

Any help would be appreciated!


回答1:


Once you have the names of the image pages, you can do this:

action=query&prop=imageinfo&iiprop=url&titles=File:Foo.jpg|File:Bar.jpg

to get the URLs of the actual images.



来源:https://stackoverflow.com/questions/4312055/programatically-determining-the-url-of-a-mediawiki-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!