通过API访问维基百科页面的主图片 [英] Accessing main picture of wikipedia page by API

查看:28
本文介绍了通过API访问维基百科页面的主图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用 API 访问任何维基百科页面的缩略图?我的意思是盒子右上角的图像.有没有相关的 API?

Is there any way I can access the thumbnail picture of any wikipedia page by using an API? I mean the image on the top right side in box. Is there any APIs for that?

推荐答案

http://en.wikipedia.org/w/api.php

看看prop=images.

它返回在解析页面中使用的图像文件名数组.然后,您可以选择进行另一个 API 调用以找出完整的图像 URL,例如:action=query&titles=Image:INSERT_EXAMPLE_FILE_NAME_HERE.jpg&prop=imageinfo&iiprop=url

It returns an array of image filenames that are used in the parsed page. You then have the option of making another API call to find out the full image URL, e.g.: action=query&titles=Image:INSERT_EXAMPLE_FILE_NAME_HERE.jpg&prop=imageinfo&iiprop=url

通过文件名的哈希计算 URL.

不幸的是,虽然 prop=images 返回的图像数组是按照它们在页面上找到的顺序,但不能保证第一个是信息框中的图像,因为有时页面将在信息框之前包含一个图像(大多数情况下是页面元数据的图标:例如这篇文章被锁定").

Unfortunately, while the array of images returned by prop=images is in the order they are found on the page, the first can not be guaranteed to be the image in the info box because sometimes a page will include an image before the infobox (most of the time icons for metadata about the page: e.g. "this article is locked").

搜索包含页面标题的第一张图像的图像数组可能是对信息框图像的最佳猜测.

Searching the array of images for the first image that includes the page title is probably the best guess for the infobox image.

这篇关于通过API访问维基百科页面的主图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆