从Google Translate抓取HTML [英] Scraping HTML from Google Translate

查看:113
本文介绍了从Google Translate抓取HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google翻译器翻译字符串.

I want to translate a string using Google Translator.

我的示例字符串是"this is my string".

我想使用HTML Agility Pack来解析HTML文档.

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

我尝试过:

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);
    }
}

但是我没有结果.

我的目的是使用Google翻译来翻译完整的字符串,并在Windows窗体的标签中显示翻译后的字符串.

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

我该怎么做?

推荐答案

这是个坏主意.正如评论员指出的那样,Google提供了程序化界面作为付费服务. Google肯定具有适当的安全功能,试图阻止您所做的一切,这就是为什么它不起作用.也许您可以使它以某种方式工作,但是即使那样,您也始终有可能会提高Google的安全性并再次阻止您的脚本.此外,您几乎肯定会违反Google的使用条款.

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更新: Microsoft Translator API 现在支持孟加拉语,并且每月免费提供多达200万个字符.

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

这篇关于从Google Translate抓取HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆