wikipedia api:仅获取解析介绍 [英] wikipedia api: get parsed introduction only

查看:33
本文介绍了wikipedia api:仅获取解析介绍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 PHP,是否有一种很好的方法可以从维基百科页面唯一获取(解析)介绍?

Using PHP, is there a nice way to get the (parsed) introduction only from a wikipedia page?

我必须采用当前方法:

  • 首先是调用api页面并返回,然后在我从第一个请求中提取的介绍上调用Wiki解析器(两个请求,从文本中提取介绍也不漂亮).
  • 第二种是调用整个页面解析器,并使用xpath来检索内容表之前的每个

    标签.

  • The first is to call the api page and return, then call the Wiki parser on the introduction I have pulled from the first request (two requests, extracting the intro from the text isn't pretty either).
  • The second is to call the entire page parser and use xpath to retrieve every <p> tag before the contents table.

使用这两种方法后,我必须重新解析 HTML 以确保介绍链接中的相关链接指向维基百科.

With both methods I then have to re-parse the HTML to ensure the relevant links inside the introduction link off to wikipedia.

两者都不理想,一定有更好的方法吗?

Neither are ideal really, there must be a better way?

推荐答案

action=parse API 模块接受一个节号参数,像这样.领先的是第 0 节.

The action=parse API module accepts a section number parameter, like this. The lead is section number 0.

这篇关于wikipedia api:仅获取解析介绍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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