使用php的Wikipedia API仅获取有关企业的信息

时间:2015-01-19 06:32:51

标签: javascript php image api wikipedia

我正在我的网站上创建搜索结果页面,我试图让它检测公司何时被搜索并从中获取维基百科脚本。

但我只希望它显示代码,如果搜索是一个类似谷歌和bing的公司

Google搜索显示公司信息的Microsoft

我有api设置来获得第一段。但现在我需要检测它是否是一个企业,获取图像,并获得创始人/首席执行官

这是我到目前为止的代码

<div style='width:400px;float:right;border-radius:5px;border:1px solid black;margin:10px 20px;'>
  <?php
     $search = urlencode($search);
     $url = 'http://en.wikipedia.org/w/api.php?action=parse&page='.$search.'&format=json&prop=text&section=0';
     $ch = curl_init($url);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($ch, CURLOPT_USERAGENT, "TestScript");
     $c = curl_exec($ch);
     $json = json_decode($c);
     $content = $json->{'parse'}->{'text'}->{'*'};
  ?>
  <div style='width:100px;height:100px;float:right;'>
     <?php
        //where i want the picture to display
     ?>
  </div>
  <div>
      <?php
          $pattern = '#<p>(.*)</p>#Us';
          if(preg_match($pattern, $content, $matches)){
              print clean(strip_tags($matches[1]));
          }
      ?>
  </div>
</div>

我已经查看了维基百科API,但我似乎无法找到任何显示它是否在关于公司的部分中,还在页面上抓取图像似乎非常滞后和不需要。还会使用JavaScript是一个更好的方式获得它,然后使用PHP?

1 个答案:

答案 0 :(得分:0)

您必须完成大部分自己的解析,但API可以肯定地用于此。