How to read the result of a Google calculation request using .net / C #?

I want to send Google requests as follows:

... from the C # console application and grab the result reported by Google (and ignore any links to other sites). Is there a specific Google API that helps me in this task?

I got this idea from the Launchy tool (launchy.net). The GCalc plugin does this, I also found the source file for this module:
http://launchy.svn.sourceforge.net/viewvc/launchy/tags/2.5/plugins/gcalc/gcalc.cpp?revision=614&view=markup

GCalc doesn't seem to use the Google API at all. But I don’t know how to do the same in C #, and I would prefer to use the correct API. But if not, I could use some hints / pointers on how to copy GCalc functionality in C # (.net libraries / classes ...?)

+4
source share
3 answers

Google calculator results are not displayed when using the API. Therefore, if you want them, you will have to clear the page. Be careful as it relates to Google’s terms of service, so your IP address will be blocked if you send too many frequent requests.

Once you have the results page, use the html parser. The result is in the <b> (for example, <b>1 + 1 = 2</b> , if it is absent, then you do not have the result of the calculator). Be careful with the <sup> tags as a result (e.g. <b>(1 (m^2) kg) / 2 = 0.5 m<sup>2</sup> kg</b> ). You can also decode html objects.

+2
source

You can use WebClient.DownloadString (string URL) . This way you get the page (html) as a string. You should analyze the result, but it should not be difficult. HttpAgilityPack is a good C # html parser that uses XPath to retrieve data.

0
source

why not use HTTPWebRequest, and then parse the result as indicated in its response by the macrograph.

0
source

Source: https://habr.com/ru/post/1334354/


All Articles