我想喝一杯啤酒并在Bing上搜索,以便从http://ratebeer.com返回结果。我得到的结果大多是好的,但有些结果(我认为)错了。
我遇到问题的啤酒之一被命名为“Kolk Maak Amber Ale”。
使用R和httr包,我的代码是:
url <- https://api.cognitive.microsoft.com/bing/v5.0/search?q=Kolk+Maak+Amber+Ale+site:http://ratebeer.com/beer&mkt=en-us
res <- GET(url,
add_headers("Ocp-Apim-Subscription-Key"=APIkey))
其中“APIkey”是Microsoft-Cognitive-Services的个人密钥。 结果是:
> content(res)
$`_type`
[1] "SearchResponse"
$webPages
$webPages$webSearchUrl
[1] "https://www.bing.com/cr?IG=8E30DC638C5B48E592061644988A6924&CID=08A1C0B86E4C6A7527FCCADF6FAB6BD5&rd=1&h=28PvtjGreQkOBLSaPy_GCtmkd-G642-BVoJp814ve_8&v=1&r=https%3a%2f%2fwww.bing.com%2fsearch%3fq%3dKolk%2bMaak%2bAmber%2bAle%2bsite%253ahttp%253a%252f%252fratebeer.com%252fbeer&p=DevEx,5148.1"
$webPages$totalEstimatedMatches
[1] 3
$webPages$value
$webPages$value[[1]]
$webPages$value[[1]]$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.0"
$webPages$value[[1]]$name
[1] "North River Grisette du Noorden - ratebeer.com"
$webPages$value[[1]]$url
[1] "https://www.bing.com/cr?IG=8E30DC638C5B48E592061644988A6924&CID=08A1C0B86E4C6A7527FCCADF6FAB6BD5&rd=1&h=71h-PtMgTQkVXsH3vxpLLwGtkRp4nyYvBbVMTwc47XM&v=1&r=https%3a%2f%2fwww.ratebeer.com%2fbeer%2fnorth-river-grisette-du-noorden%2f492033%2f&p=DevEx,5056.1"
$webPages$value[[1]]$displayUrl
[1] "https://www.ratebeer.com/beer/north-river-grisette-du-noorden/492033"
$webPages$value[[1]]$snippet
[1] "North River Grisette du Noorden a Traditional Ale beer by North ... Pours a hazed amber with a medium ... Jopen Stripbier 2016: Tania (Hanco Kolk) 82 Jopen Koyt 94"
$webPages$value[[1]]$dateLastCrawled
[1] "2017-04-13T12:56:00"
$webPages$value[[2]]
$webPages$value[[2]]$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.1"
$webPages$value[[2]]$name
[1] "Frankenheim Alt - ratebeer.com"
$webPages$value[[2]]$url
[1] "https://www.bing.com/cr?IG=8E30DC638C5B48E592061644988A6924&CID=08A1C0B86E4C6A7527FCCADF6FAB6BD5&rd=1&h=-1irhi3khCoAu383TebZwPJdZMjMAL9L5KH6Nfs668U&v=1&r=https%3a%2f%2fwww.ratebeer.com%2fbeer%2ffrankenheim-alt%2f11335%2f&p=DevEx,5068.1"
$webPages$value[[2]]$displayUrl
[1] "https://www.ratebeer.com/beer/frankenheim-alt/11335"
$webPages$value[[2]]$snippet
[1] "... donkere mouten, aangebrande caramel, metalig bitter, aards, noten, nee hier maak je ... Bottle 3 cl. Pours a hazy amber with a ... Element Interval Ale ..."
$webPages$value[[2]]$dateLastCrawled
[1] "2017-04-11T15:13:00"
$webPages$value[[3]]
$webPages$value[[3]]$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.2"
$webPages$value[[3]]$name
[1] "Cervoise Lancelot - ratebeer.com"
$webPages$value[[3]]$url
[1] "https://www.bing.com/cr?IG=8E30DC638C5B48E592061644988A6924&CID=08A1C0B86E4C6A7527FCCADF6FAB6BD5&rd=1&h=Fsu_98e2uQEcyl7FovpvzwTjtwLnOJvGezmVQvKAbPY&v=1&r=https%3a%2f%2fwww.ratebeer.com%2fbeer%2fcervoise-lancelot%2f9828%2f&p=DevEx,5080.1"
$webPages$value[[3]]$displayUrl
[1] "https://www.ratebeer.com/beer/cervoise-lancelot/9828"
$webPages$value[[3]]$snippet
[1] "Cervoise Lancelot a Traditional Ale beer by Lancelot, ... Slightly hazy amber with quick diminishing head. Sweet malts, ... (Hanco Kolk) 82"
$webPages$value[[3]]$dateLastCrawled
[1] "2017-04-13T18:28:00"
$rankingResponse
$rankingResponse$mainline
$rankingResponse$mainline$items
$rankingResponse$mainline$items[[1]]
$rankingResponse$mainline$items[[1]]$answerType
[1] "WebPages"
$rankingResponse$mainline$items[[1]]$resultIndex
[1] 0
$rankingResponse$mainline$items[[1]]$value
$rankingResponse$mainline$items[[1]]$value$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.0"
$rankingResponse$mainline$items[[2]]
$rankingResponse$mainline$items[[2]]$answerType
[1] "WebPages"
$rankingResponse$mainline$items[[2]]$resultIndex
[1] 1
$rankingResponse$mainline$items[[2]]$value
$rankingResponse$mainline$items[[2]]$value$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.1"
$rankingResponse$mainline$items[[3]]
$rankingResponse$mainline$items[[3]]$answerType
[1] "WebPages"
$rankingResponse$mainline$items[[3]]$resultIndex
[1] 2
$rankingResponse$mainline$items[[3]]$value
$rankingResponse$mainline$items[[3]]$value$id
[1] "https://api.cognitive.microsoft.com/api/v5/#WebPages.2"
正如您在此处所见,列出的三种啤酒中没有一种显示正在搜索的啤酒(Kolk Maak Amber Ale)。但是,如果我按照
中的搜索响应链接content(res)$webPages$webSearchUrl
[1] "https://www.bing.com/cr?IG=8E30DC638C5B48E592061644988A6924&CID=08A1C0B86E4C6A7527FCCADF6FAB6BD5&rd=1&h=28PvtjGreQkOBLSaPy_GCtmkd-G642-BVoJp814ve_8&v=1&r=https%3a%2f%2fwww.bing.com%2fsearch%3fq%3dKolk%2bMaak%2bAmber%2bAle%2bsite%253ahttp%253a%252f%252fratebeer.com%252fbeer&p=DevEx,5148.1"
使用浏览器(Chrome / Firefox / IE)我得到了正确的啤酒作为第一个结果。
为什么会这样?为什么所有搜索值都返回错误的网址,但使用物理浏览器返回正确的网址?我已经测试过的其他啤酒返回了正确的网址。
答案 0 :(得分:0)
这非常有趣。如果您在搜索框中输入此内容,并使用加号,您可以从Bing获得正确的结果。没有他们,你就没有得到正确的页面:
科尔克+ Maak +琥珀+啤酒+站点:ratebeer.com
此外,此版本提供了正确的结果: 网站:ratebeer.com Kolk Maak ale amber
但是这个版本不起作用: 网站:ratebeer.com Kolk Maak琥珀啤酒