Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different results using Bing.com and Bing Search API

I'm using the Bing Search API 2.0 (XML) & PHP to retreive results.
But when running some queries, the API doesn't return the (same) results Bing.com would.

When I send this request: (This is using the API)

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

I get 0 results.

But if I go to Bing.com and search for bacon the URL would be:

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

So If I take I substitute in my API query into this URL like so:

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

I should get 0 results again, right?

No, I get the 1 result. (The result I was looking for with the API).
Why is this? Is there anyway around this?

like image 535
Adam Lynch Avatar asked Apr 27 '11 13:04

Adam Lynch


1 Answers

Yes the Bing API is totally brain dead and utterly useless because of this fact.

But, luckily, screen scraping is trivial:

<?

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"));
like image 120
Byron Whitlock Avatar answered Sep 22 '22 01:09

Byron Whitlock