首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wikipedia API --提取内容框

Wikipedia API --提取内容框
EN

Stack Overflow用户
提问于 2014-01-30 14:00:34
回答 1查看 1K关注 0票数 1

我正在尝试提取灰色框(摘要/信息框)中的链接信息,例如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 --它只返回摘要。

我试着用沙盒做实验,但我不知道如何提取灰盒中具体包含的信息。

EN

回答 1

Stack Overflow用户

发布于 2014-02-08 22:50:16

您可以使用PHP Simple HTML DOM Parser

代码语言:javascript
复制
<?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]

}

?>

如果这个答案适合你的需要,请选择它作为最佳答案,并提升它,因为它花了我很大的努力。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21448963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档