Scraping HTML from Google Translate

.net c# google-translate html-agility-pack winforms

Question

I want to translate a string using Google Translator.

My sample string is "this is my string".

I want to use HTML Agility Pack to parse HTML documents.

I tried this:

using HtmlAgilityPack; 

........

var webGet = new HtmlWeb();
var document = webGet.Load(
    "http://translate.google.com/#en/bn/this%20is%20my%20string");

var node = document.DocumentNode.SelectNodes(
    "//span[@class='short_text' and @id='result_box']");

if (node != null)
{
    foreach (var xx in node)
    {
        x = xx.InnerText;
        MessageBox.Show(x);
    }
}

But I get no results.

My aim is to translate a complete string using Google Translate and to show the translated string in a label in Windows Forms.

How can I do this?

Popular Answer

This is a bad idea. As commenters have pointed out, Google offers a programmatic interface as a paid service. Google surely has security features in place to try to block exactly what you are doing, and that is why it isn't working. Perhaps you could get it working somehow, but even then you would always be in danger of Google improving its security and your script being blocked again. In addition, you are almost certainly breaking the Google terms of use.

2017 Update: Microsoft Translator API now supports Bengali, and is free for up to two million characters per month.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why