Php 从MediaWiki API调用中提取内容(XML、cURL)
网址: 这将输出如下内容:Php 从MediaWiki API调用中提取内容(XML、cURL),php,parsing,curl,mediawiki,xml-parsing,Php,Parsing,Curl,Mediawiki,Xml Parsing,网址: 这将输出如下内容: http://en.wikipedia.org/w/api.php?action=parse&prop=text&page=Lost_(TV_series)&format=xml 下一步是什么?用于解析它。这样做: $html = curl_exec($curl_handle); //您已经在$html中输入了文本 $html='text…'; //解析从这里开始: $doc=新的DOMDocument(); @$doc->loadHTML
http://en.wikipedia.org/w/api.php?action=parse&prop=text&page=Lost_(TV_series)&format=xml
下一步是什么?用于解析它。这样做:
$html = curl_exec($curl_handle);
//您已经在$html中输入了文本
$html='text…';
//解析从这里开始:
$doc=新的DOMDocument();
@$doc->loadHTML($html);
$nodes=$doc->getElementsByTagName('text');
//显示您需要的内容:
echo$nodes->item(0)->nodeValue;
这将产生:
文本
$html = curl_exec($curl_handle);
//you already have input text in $html
$html = '<api><parse><text xml:space="preserve">text...</text></parse></api>';
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('text');
//display what you need:
echo $nodes->item(0)->nodeValue;