从搜索页面获取Bing结果

时间:2013-06-27 20:52:31

标签: bing

我想在不使用api的情况下获得bing结果,我希望使用php直接从bing页面获取它们。我不知道怎么做。

3 个答案:

答案 0 :(得分:0)

您可以使用http请求并将结果削减以获得所需内容 你可以使用正则表达式

示例:

$ results = file_get_contents(“http://www.bing.com/search?q=regular+expressions”);

您将找到该页面的所有HTML内容,就像您点击“查看页面来源”

时所看到的那样

然后在其上应用正则表达式以提取结果

答案 1 :(得分:0)

查看此脚本:http://www.fromzerotoseo.com/scraping-bing-serp/

特别是抓取链接的正则表达式搜索:

preg_match_all( '(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU', $result['EXE'], $matches);

答案 2 :(得分:0)

只需使用simple_html_dom并进行简单的解析即可。要获得bing结果,您必须找到一个名为“sb_count”的特定类。如果您需要链接,请通过“b_attribution”更改类以获取所有链接。 您可以使用foreach:

循环执行结果页面,执行以下查询
include_once 'simple_html_dom.php';
header('Content-Type: text/html; charset=ISO-8859-2'); 

$html = new simple_html_dom();
$param = 'Your query';
$html -> load_file('https://www.bing.com/search?q=' . $param . '&go=Submit&qs=n&form=QBLH&pq=' . $param . '&sc=8-6&sp=-1&sk=&ghc=1&cvid=e3777d60b1f04c90a3d8f08903433c7a');
    foreach ( $html->find('.sb_count') as $post){
        echo  '<p>' . $post . '</p>';
    }
相关问题