admin管理员组

文章数量:1567750

Google翻译

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace Google
{
    class Program
    {
        static void Main(string[] args)
        {
            Google();
            Console.ReadKey();
        }

        public static void Google()
        {
            string url = "https://translate.google/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&bl=boq_translate-webserver_20210927.13_p0&soc-app=1&soc-platform=1&soc-device=1&rt=c";
            string q = "The invention relates to a \"three-dimensional structure\" obtained from a tubular preform, which is obtained from a net of the Chebyshev type (with such a structure also being called \"elastic gridshell\") having a flared shape maintained by means selected from the group comprising hoops (5, 7, 9), spacers (11) and cables (11). The invention also relates to a method for installing such a structure, in which method the tubular preform is brought to the installation point, then deformations are applied to this preform that allow the final desired flared shape to be achieved. Particular application to the production of street furniture allowing shaded areas to be created in towns by cultivating everything that is fixed on a heavy container containing cultivated soil and the necessary devices.";
            string from = "auto";
            string to = "zh";
            var from_data = "f.req=" + System.Web.HttpUtility.UrlEncode(
                string.Format("[[[\"MkEWBc\",\"[[\\\"{0}\\\",\\\"{1}\\\",\\\"{2}\\\",true],[null]]\", null, \"generic\"]]]",
                ReplaceString(q), from, to), Encoding.UTF8).Replace("+", "%20");
            byte[] postData = Encoding.UTF8.GetBytes(from_data);
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            client.Headers.Add("ContentLength", postData.Length.ToString());
            client.Headers.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36");
            byte[] responseData = client.UploadData(url, "POST", postData);
            string content = Encoding.UTF8.GetString(responseData);
            Console.WriteLine(MatchResult(content));
        }

        /// <summary>
        /// 匹配翻译结果
        /// </summary>
        /// <returns></returns>
        public static string MatchResult(string content)
        {
            string result = "";
            string patttern = @",\[\[\\\""(.*?)\\\"",";
            Regex regex = new Regex(patttern);
            MatchCollection matchcollection = regex.Matches(content);
            if (matchcollection.Count > 0)
            {
                List<string> list = new List<string>();
                foreach (Match match in matchcollection)
                {
                    list.Add(match.Groups[1].Value);
                }
              

本文标签: 几种在线翻译