使用Bing.com和Bing搜索API得到不同的结果



我正在使用必应搜索API 2.0 (XML) &PHP检索结果。
但是当运行一些查询时,API不会返回Bing.com会返回的(相同的)结果。

当我发送这个请求时:(这是使用API)

http://api.search.live.net/xml.aspx?Appid=__________&query=3+ts+site%3Amycharity.ie/charity&sources=web&web.count=10&web.offset=0

我得到0个结果。

但是如果我去bing。com搜索bacon URL会是:

http://www.bing.com/search?q=bacon&go=&form=QBRE&filt=all&qs=n&sk=&sc=8-5

我将API查询代入URL,像这样:

http://www.bing.com/search?q=3+ts+site%3Amycharity.ie/charity&go=&form=QBRE&filt=all&qs=n&sk=&sc=8-5

结果应该还是0,对吧?

不,我得到的结果是1。

为什么会这样?还有别的办法吗?

是的,Bing API完全是脑死亡,完全没用,因为这个事实。

但是,幸运的是,屏幕抓取很简单:

<?
function searchBing($search_term)
{       
    $html = file_get_contents("http://www.bing.com/search?q=".urlencode($search_term)."&go=&qs=n&sk=&sc=8-20&first=$start&FORM=QBLH");
    $doc = new DOMDocument();
    @$doc->loadHtml($html);
    $x = new DOMXpath($doc);
    $output = array();
    // just grab the urls for now
    foreach ($x->query("//div[@class='sb_tlst']//a") as $node)          
    {
        $output[] = $node->getAttribute("href");
    }
    return $output;
}
print_r(searchBing("bacon"));

看起来不像API请求实际上是在请求信息。是的,但不完全是。例子;从必应搜索;"search?q=bacon&go=&form"注意里面有bacon这个词。在API请求中,这似乎没有以任何方式被解析。甚至不是十六进制值。我认为这就是问题所在。

可能有问题,现在已经修复了…

目前,如果我正在尝试根据Bing API 2.0 MSDN进行以下查询,它们都返回相同的单个结果:

http://www.bing.com/search?q=3+ts+site%3Amycharity.ie/charity&go=&form=QBRE&filt=all&qs=n&sk=&sc=8-5
http://api.bing.net/xml.aspx?Appid=______7&query=3+ts+site%3Amycharity.ie/charity&sources=web
http://api.bing.net/json.aspx?Appid=_______&query=3+ts+site%3Amycharity.ie/charity&sources=web

最新更新