Hello There, Guest!
View New Posts  |  View Today's Posts
[C#] Bing Suggestions API Parsing Example/Demo

  • 0 Vote(s) - 0 Average


03-04-2013, 04:56 AM #1
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

Bing Suggestions API Parsing Example/Demo
So I came across a cool Bing API today that I didn't know about. And decided to see how it worked.

Code:
public static void MainMethod()
{
    string input;
    WebClient wc = new WebClient();

    while (!(input = GetUserInput()).Equals("q", StringComparison.OrdinalIgnoreCase))
    {
        int i = 1;
        string[] data = wc.DownloadString(@"http://api.bing.com/qsonhs.aspx?FORM=ASAPIH&q=" + input).Split("{}[],".ToArray());
        foreach (string part in data)
        {
            if (part.StartsWith("\"Txt\":"))
            {
                Console.WriteLine("{0}. {1}", i++, part.Substring(part.IndexOf(':') + 2, part.Length - 8));
            }
        }
        Console.WriteLine("\nPress any key to continue...");
        Console.ReadKey();
    }
}

private static string GetUserInput()
{
    Console.Clear();
    Console.Write("Enter Q to quit, or type in a query: ");
    return Console.ReadLine();
}



It basically takes in a query, and returns relevant suggestions based on that query. Could be useful :)

It returns a page with JSON formatted results and various other data, so I'm parsing from that.
This post was last modified: 03-04-2013, 04:57 AM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

03-04-2013, 05:02 AM #2
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Bing Suggestions API Parsing Example/Demo
Laugh ... It is funny to quickly see what the most popular searches are based on some relevant return values.

edit: I typed in "bob" to see if "bob marley" would be first, but it makes #3 instead...

Good god. "50" returns "50 shades of grey"

Just "f"... returns "facebook", scary even though I already had the impression that it would be #1.
This post was last modified: 03-04-2013, 05:04 AM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

03-04-2013, 10:34 PM #3
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: Bing Suggestions API Parsing Example/Demo
This is a neat little app. Does this not require an API key?
This post was last modified: 03-04-2013, 10:40 PM by KoBE.

03-04-2013, 11:04 PM #4
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Bing Suggestions API Parsing Example/Demo
(03-04-2013, 10:34 PM)KoBE Wrote:  This is a neat little app. Does this not require an API key?

Nope! That's the beauty of this :) There are others out there that do I believe, but this one doesn't seem to require one. It is fast though, because it just loads a little short snippet of JSON, and nothing else.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
Information  [Help] Grab Link From Bing Or Google userspassw0rd 12 6,227 03-12-2014, 08:20 PM
Last Post: Lee Stevens
   Win8StartForm Example/Demo AceInfinity 2 1,992 01-25-2013, 11:07 PM
Last Post: AceInfinity
   Control Demo with Voice Synthesizer Added william7 37 14,646 01-14-2013, 04:35 PM
Last Post: william7
Question  [Help] Parsing an XML file into a C# object kevorz 35 15,216 01-11-2013, 01:51 PM
Last Post: AceInfinity
   Managed DirectX - XAudio2 Demo AceInfinity 2 2,665 01-04-2013, 01:56 AM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)