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?
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With