问题
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