我正在尝试提取灰色框(摘要/信息框)中的链接信息,例如http://en.wikipedia.org/wiki/DressBarn (灰色框/右栏中的信息,如类型等)。
我正在使用这个http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&exintro&titles=DressBarn&format=json&redirects&inprop=url&indexpageids --它只返回摘要。
我试着用沙盒做实验,但我不知道如何提取灰盒中具体包含的信息。
发布于 2014-02-08 22:50:16
您可以使用PHP Simple HTML DOM Parser。
<?php
//The folder where you uploaded simple_html_dom.php
require_once('/homepages/0/d502303335/htdocs/js/simple_html_dom.php');
//Wikipedia page to parse
$html = file_get_html('https://en.wikipedia.org/wiki/Burger_King');
foreach ( $html->find ( 'table[class=infobox vcard]' ) as $element ) {
$cells = $element->find('td');
$i = 0;
foreach($cells as $cell) {
$left[$i] = $cell->plaintext;
if (!(empty($left[$i]))) {
$i = $i + 1;
}
}
$cells = $element->find('th');
$i = 0;
foreach($cells as $cell) {
$right[$i] = $cell->plaintext;
if (!(empty($right[$i]))) {
$i = $i + 1;
}
}
print_r ($right);
echo "<br><br><br>";
print_r ($left);
//If you want to know what kind of industry burger king is
echo "Burger king is $right[2], $left[2]
}
?>如果这个答案适合你的需要,请选择它作为最佳答案,并提升它,因为它花了我很大的努力。
https://stackoverflow.com/questions/21448963
复制相似问题