Last active
August 16, 2022 00:48
-
-
Save DBremen/5d23e1fb604797d12953 to your computer and use it in GitHub Desktop.
Usage of Bing Search and Synonyms API through PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://datamarket.azure.com/account/keys | |
#Home -> My Account -> Account Keys: | |
#based on http://www.powershelladmin.com/wiki/Accessing_the_Bing_Search_API_v2_using_PowerShell | |
function Get-BingSearchResult($query){ | |
Add-Type -Assembly System.Web | |
$Key = 'YOURACCOUNTKEY' | |
$Base64KeyBytes = [byte[]] [Text.Encoding]::ASCII.GetBytes("ignored:$Key") | |
$Base64Key = [Convert]::ToBase64String($Base64KeyBytes) | |
$QueryString = '%27' + [Web.HttpUtility]::UrlEncode($query) + '%27' | |
$Uri = 'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&$top=10&Query=' + $QueryString | |
$Results = Invoke-RestMethod -Uri $Uri -Headers @{ Authorization = "Basic $Base64Key" } | |
$Results.d.results | Select Title, Description, DisplayUrl, Url | |
} | |
function Get-BingSynonym($query){ | |
Add-Type -Assembly System.Web | |
$Key = YOURACCOUNTKEY' | |
$Base64KeyBytes = [byte[]] [Text.Encoding]::ASCII.GetBytes("ignored:$Key") | |
$Base64Key = [Convert]::ToBase64String($Base64KeyBytes) | |
$QueryString = '%27' + [Web.HttpUtility]::UrlEncode($query) + '%27' | |
$Uri = 'https://api.datamarket.azure.com/Bing/Synonyms/v1/GetSynonyms?Query=' + $QueryString | |
$Results = Invoke-RestMethod -Uri $Uri -Headers @{ Authorization = "Basic $Base64Key" } | |
($Results | foreach {$_.content.properties.Synonym}).'#text' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment