维基百科API没有为某些查询返回任何内容


Wikipedia API not returning anything for some queries

HTML

<html>
<head>
</head>
<form action="check2.php" method="POST">
    Search <input type="text" name="search" />
    <input type="submit" name="searchbtn" value="search" />
</form>
</body>
</html>

PHP

<?php
    $string = $_POST['search'];
    $convert = rawurlencode($string);
    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles='.$convert;
    if($_POST['search'] != '' || $_POST['search'] != null) {
        $ch = curl_init($url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $c = curl_exec($ch);
        echo $c;
    } else {
    }
?>

如果我搜索(例如)"New York",它会返回XML,但如果我搜索"Singapore Zoo",则不返回任何内容

首先,您应该设置一个用户代理。其次,这不是搜索,而是导出特定标题的页面;您正在寻找action=opensearch。

https://en.wikipedia.org/w/api.php?action=opensearch&search=api&limit=1&namespace=0&search=新加坡动物园&utf8=true给出:

["Singapore_Zoo",["Singapore Zoo"],["The Singapore Zoo (Chinese: 新加坡动物园; pinyin: Xīnjiāpō Dòngwùyuán; Malay: 'Taman Haiwan Singapura'; Tamil: சிங்கப்பூர் விலங்குக் காட்சிச்சாலை), formerly known as the Singapore Zoological Gardens and commonly known locally as the Mandai Zoo, occupies 28 hectares (69 acres) on the margins of Upper Seletar Reservoir within Singapore's heavily forested central catchment area."],["https://en.wikipedia.org/wiki/Singapore_Zoo"]]