Different results using Bing.com and Bing Search API
I'm using the Bing Search AP开发者_StackOverflowI 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"));
Doesnt look like the API request is actually requesting the information. Well, it is, but not quite. Example; from the bing search; "search?q=bacon&go=&form" Note the word bacon in it. This doesnt appear to be parsed in any way in the API request. Not even as a hex value. I believe that herein lies the problem.
Perhaps there was an issue, which is now fixed...
Currently, if I'm trying the following queries made according to the Bing API 2.0 MSDN they all return the same single result:
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
精彩评论