Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Created September 18, 2015 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayne-o/0265cec2614e8a66757d to your computer and use it in GitHub Desktop.
Save wayne-o/0265cec2614e8a66757d to your computer and use it in GitHub Desktop.
using google
class Program
{
private const string Xpath = "//*[@id=\"cwos\"]";
static void Main(string[] args)
{
var val = string.Empty;
var num1 = Convert.ToInt32(args[0]);
var num2 = Convert.ToInt32(args[1]);
var task = Task.Run(async () =>
{
using (var client = new HttpClient())
{
var url = "http://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=" + num1 + "*" + num2;
var responseString = await client.GetStringAsync(url);
var doc = new HtmlDocument();
doc.LoadHtml(responseString);
var node = doc.DocumentNode.SelectNodes(Xpath)[0];
val = node.Attributes["value"].Value;
}
});
Task.WaitAll(new[] { task });
Console.WriteLine(val);
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment