如何从维基百科获取信息到我的应用程序中

发布于 2024-07-19 03:37:00 字数 108 浏览 4 评论 0原文

大家好,我希望从维基百科获取数据库中条目的信息,例如一些体育场和国家/地区信息。 我正在使用 Zend Framework,并且我如何能够处理返回多个不明确条目等的查询。我希望在这里获得所有帮助...

Hi guys I wish to get information for entries I have in my database from wikipedia like for example some stadiums and country information. I'm using Zend Framework and also how would I be able to handle queries that return multiple ambiguous entries or the like.. I would like all the help I can get here...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美羊羊 2024-07-26 03:37:00

Wikipedia 基于 MediaWiki,提供应用程序可编程接口 (API)。

您可以在 Wikipedia 上查看 MediaWiki API - http://en.wikipedia.org/w/api .php

MediaWiki API 文档 - http://www.mediawiki.org/wiki/API

Wikipedia is based on MediaWiki, offering an Application Programmable Interface (API).

You can check out MediaWiki API on Wikipedia - http://en.wikipedia.org/w/api.php

Documentation for MediaWiki API - http://www.mediawiki.org/wiki/API

梦初启 2024-07-26 03:37:00

对您要导入的文章执行一个简单的 HTTP 请求这里有一个很好的库,它可能有助于解析 HTML,尽管有数十种解决方案包括使用 php 提供的标准 DOM 模型

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://www.yahoo.com/");
if (!PEAR::isError($req->sendRequest())) {
    echo $req->getResponseBody();
}
?> 

请注意,如果您的流量水平被认为过高,您将被锁定在该网站之外。 (如果您想要大量文章,下载数据库

Do a simple HTTP request to the article you are looking to import. Here's a good library which might help with parsing the HTML, though there are dozens of solutions for that as well, including using the standard DOM model which is provided by php.

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://www.yahoo.com/");
if (!PEAR::isError($req->sendRequest())) {
    echo $req->getResponseBody();
}
?> 

Note, you will be locked out of the site if your traffic levels are deemed too high. (If you want a HUGE number of articles, download the database)

牵强ㄟ 2024-07-26 03:37:00

这个博客有一个非常好的代码从 wiki 获取定义

<?php
//FUNCTION THAT :PARAMETER - KEYWORD , AND RETURNS WIKI DEFINITION (IN ARRAY FORMAT)
function wikidefinition($s) {
//ENGLISH WIKI
    $url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    curl_setopt($ch, CURLOPT_POST, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");

    $page = curl_exec($ch);
    $xml = simplexml_load_string($page);
    if((string)$xml->Section->Item->Description) {
        return array((string)$xml->Section->Item->Text, 
                     (string)$xml->Section->Item->Description, 
                     (string)$xml->Section->Item->Url);
    } else {
        return "";
    }
}
//END OF FUNCTION WIKIDEFINITIONS


//USE OF FUNCTION
$data = wikidefinition('Bangladesh') ;
//var_dump( wikidefinition('bangladesh') ) ; //displays the array content
echo "Word:"       . $data[0] . "<br/>";
echo "Definition:" . $data[1]  . "<br/>";
echo "Link:"       . $data[2] . "<br/>";

?>

This blog has a really good code for get a definition from wiki

<?php
//FUNCTION THAT :PARAMETER - KEYWORD , AND RETURNS WIKI DEFINITION (IN ARRAY FORMAT)
function wikidefinition($s) {
//ENGLISH WIKI
    $url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    curl_setopt($ch, CURLOPT_POST, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");

    $page = curl_exec($ch);
    $xml = simplexml_load_string($page);
    if((string)$xml->Section->Item->Description) {
        return array((string)$xml->Section->Item->Text, 
                     (string)$xml->Section->Item->Description, 
                     (string)$xml->Section->Item->Url);
    } else {
        return "";
    }
}
//END OF FUNCTION WIKIDEFINITIONS


//USE OF FUNCTION
$data = wikidefinition('Bangladesh') ;
//var_dump( wikidefinition('bangladesh') ) ; //displays the array content
echo "Word:"       . $data[0] . "<br/>";
echo "Definition:" . $data[1]  . "<br/>";
echo "Link:"       . $data[2] . "<br/>";

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文