「Continue」または「query-continue」コマンドで Mediawiki API を使用して、wiki 記事から情報を引き出すのに助けが必要です。多数の wiki 記事 (現在 800 以上) があり、API を使用してそれらを 50 のバッチで取得し、セクションを印刷する必要があります。
私の API 呼び出しは正しく動作します:
//Stackoverflow により、ここで有効な URL を使用できます。この API は、実際には私自身のローカルホスト サーバーです http://en.wikipedia.org/w/api.php?action=query&list=allpages&apfrom=a&apto=z&apnamespace=0&format=xml&aplimit=50 私はすべてのページを照会しているため、「apfrom」と「apto」です。
PHP と CURL を使用してコードを処理し、API にアクセスして 50 個のバッチを処理し、「続行」を使用して最後までレコードにアクセスする方法を教えてください。これまでのところ、私のphpコードは次のとおりです。
//the CURL commands here work and outputs a data set but only for the first 50 records, so I need to call "continue" to get to the end.
//My api url is localhost but I'm forced to use a valid URL by Stackoverflow.com
$url = sprintf('http://en.wikipedia.org/w/api.php?
action=query&list=allpages&apfrom=a&apto=z&apnamespace=0&format=xml&aplimit=50');
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'My site');
$res = curl_exec($ch);
$continue = '';
while ( // I don't know what to set here as true to get the while loop going, maybe continue = true? maybe set query-continue as true?)
{
//Maybe I need something other than $res['query-continue]??
if (empty($res['query-continue']))
{
exit;
}
else
{
$continue = '&apcontinue='.urlencode($res['query-continue']);
foreach ($res['query']['allpages'] as $v)
{
echo $v['title'];
}
}
}
上記の while ループ コードを修正して、ループ内の各 wiki 記事からタイトルを簡単に出力できるようにしてもらえますか? ネットで色々調べたけど行き詰った!! http://www.mediawiki.org/wiki/API:Queryで Python ループの例を見つけました が、PHP で実行する必要があります。そして、continue と query-continue のどちらを呼び出すかはわかりません。