我正在尝试将搜索到的维基百科文章内容的内容检索到我的页面。这是我的$url
Pink Floyd和我的代码 -
$curl = curl_init();
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( "Cache-Control: max-age=0",
"Connection: keep-alive",
"Keep-Alive: 300",
"Accept-Charset: ISO-8859-1,utf-8",
"Accept-Language: $wikibox_options[language]",
"Pragma: " ) );
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_USERAGENT, WIKIBOX_AGENT );
curl_setopt( $curl, CURLOPT_ENCODING, 'gzip,deflate' );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 120 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 120 );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 5 );
if ( $post ) {
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, http_build_query( $post_content ) );
}
$result = curl_exec( $curl );
curl_close( $curl );
但是$result
什么都没打印。提前谢谢。
答案 0 :(得分:1)
你可以改为
<?php
$result = file_get_contents('https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Pink_Floyd');
echo $result;
?>