开发者

Programatically determining the URL of a MediaWiki image

开发者 https://www.devze.com 2023-01-27 19:07 出处:网络
I\'m trying to download images from specific MediaWiki pages (Or just specific images) using a PHP script.

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 followi开发者_如何学JAVAng 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消