Hello Readers,

In Today’s Blog post we’ll talk about the Bing API and how Bing Search Autocomplete data can be fetched using PowerShell.

bing

I was playing around with Web Debugger Tool (Fiddler) and while doing a Bing search I noticed my Browser making HTTP request to Bing API URL.
Well API’s are always fun, so why not try and explore it with PowerShell 😉

bing


HOW IT WORKS

Before we proceed further time for some definitions 🙂 so that all have same understanding –

APIApplication Programming Interface is a set of functions and procedures that allow the creation of applications that access the features or data of an operating system, application, or another service.

REST – REST stands for Representational State Transfer. (It is sometimes spelled “ReST“.) It relies on a stateless, client-server, cacheable communications protocol, and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications.

API’s which return Richly Structured data are called RESTFull API’s.

So, making it work is 3 step process :

  1. Make your Custom Query URL –

    Like Fiddler Logs in the above screenshot, we’ll create a URL with a Custom Query string, something like below –URL :  http://api.bing.com/qsml.aspx?query=WordWhen you type this URL in a browser address bar and hit enter, you’ll see a structured data returned (XML Data).

    bing

  2. Send HTTP request to Bing API –

    Using the PowerShell Invoke-RestMethod Cmdlet sending an HTTP request on the URL mentioned in Step 1.

    Function Auto-Complete()
    {
    Return (Invoke-RestMethod -Uri "http://api.bing.com/qsml.aspx?query=$($TextBox1.text)").searchsuggestion.section.item.text
    }
  3. Data Mine the Structured Data returned –

    Capture the useful information from the Structured data returned from the API and feed it to your GUI.


SCRIPT

https://gist.github.com/PrateekKumarSingh/cbcac3a41450811044f9#file-auto-complete-ps1


HOW TO USE IT

Run the Script and type in your query in the TextBox. The form is intelligent enough to give you suggestions the moment you stop typing, like in the below animation

ezgif.com-video-to-gif (3)

Optical Character Recognition

Author of “PowerShell Guide to Python“, “Windows Subsystem for Linux (WSL)” and currently writing the most awaited book: “PowerShell to C# and Back” !


Subscribe to our mailing list

* indicates required