I'm trying to make a simple translator for chinese website using DeepL Traslator, got the data from Live http header
thank in advance --- thank in advance ---- thank in advance
thank in advance --- thank in advance --- thank in advance
thank in advance --- thank in advance --- thank in advance
POST https://www2.deepl.com/jsonrpc HTTP/1.1 Host: www2.deepl.com Connection: keep-alive Content-Length: 211 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Content-type: application/json Accept: */* Origin: https://www.deepl.com Sec-Fetch-Site: same-site Sec-Fetch-Mode: cors Sec-Fetch-Dest: empty Referer: https://www.deepl.com/ Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9
{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"武术永生继承体系的最新篇章","raw_en_context_before":[],"raw_en_context_after":[],"preferred_num_beams":4,"quality":"fast"}],"lang":{"user_preferred_langs":["EN","DE","ZH"],"source_lang_user_selected":"ZH","target_lang":"EN"},"priority":-1,"commonJobParams":{},"apps":{"usage":1},"timestamp":1600378823885},"id":54410005}
HTTP/2.0 200 OK
Server: nginx
Date: Thu, 17 Sep 2020 21:40:25 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 859
access-control-allow-credentials: true
access-control-allow-origin: https://www.deepl.com
Set-Cookie: LMTBID=v2|ae55c469-ae91-4753-8847-d9089c7b4696|2b3201e8abd3891c9bbd6cb6b07eb778; Version=1; Path=/; Domain=.deepl.com; Secure; HttpOnly; Expires=Wed, 17-Mar-2021 00:00:00 GMT
X-Firefox-Spdy: h2
{"jsonrpc":"2.0","id":54410005,"result":{"translations":[{"beams":[{"postprocessed_sentence":"The latest chapter of the Martial Immortal Inheritance System","num_symbols":17,"score":-4996.555932850418,"totalLogProb":6.38829182947645},{"postprocessed_sentence":"The latest chapter of the Wuxian Inheritance System","num_symbols":15,"score":-4996.682360226365,"totalLogProb":6.210432005285439},{"postprocessed_sentence":"The latest chapter of the Martial Immortal Legacy System","num_symbols":15,"score":-4996.792936387164,"totalLogProb":6.003439753290133},{"postprocessed_sentence":"The newest chapter of the Martial Immortal Inheritance System","num_symbols":18,"score":-4997.178788573046,"totalLogProb":5.208891251223198}],"quality":"normal"}],"target_lang":"EN","source_lang":"ZH","source_lang_is_confident":true,"timestamp":1600378825,"date":"20200917"}}
this my full code, Sorry I'm just a beginner So... lol but got Empty Result Not Sure what's the problem...
using System;
using System.Net.Http;
using System.Windows.Forms;
using HtmlAgilityPack;
using System.Linq;
using System.Data;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.IO;
namespace translate2test
{
public partial class Form1 : Form
{
DataTable table;
string firstData = Interaction.InputBox("Enter your URL", "My Novel Reaser", "Let's have fun", 200, 200);
public Form1()
{
InitializeComponent();
if (firstData != "")
test(firstData);
}
// TODO: get data from "https://tw.uukanshu.com/b/52103/17208.html" and dump it in textbox
public async void test(string MyURL)
{
// string MyURL = txtURL.Text;
HtmlWeb web = new HtmlWeb();
var doc = await Task.Factory.StartNew(() => web.Load(MyURL));
var title = doc.DocumentNode.SelectNodes(@"//*[@id=""timu""]")
.Select(node => node.InnerText);
var firsttext = doc.DocumentNode.SelectNodes(@"//*[@id=""contentbox""]/text()[2]")
.Select(node => node.InnerText);
var theOtherText = doc.DocumentNode.SelectNodes(@"//*[@id=""contentbox""]//p")
.Select(node => node.InnerText);
table = new DataTable("Datatabletranslator");
table.Columns.Add("Paragraph", typeof(string));
foreach (string items in title)
{
table.Rows.Add(items);
}
foreach (string items in firsttext)
{
table.Rows.Add(items);
}
foreach (string items in theOtherText)
{
table.Rows.Add(items);
}
for (int i = 0; i < table.Rows.Count; i++)
{
txtCollectFull.Text = txtCollectFull.Text + " " + table.Rows[i][0].ToString().Trim();
}
}
private void btnGo_Click(object sender, EventArgs e)
{
deeptest();
}
public class DateHelper
{
public static double DateTimeToUnixTimestamp(DateTime dateTime)
{
return (TimeZoneInfo.ConvertTimeToUtc(dateTime) -
new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds;
}
}
public async void deeptest()
{
double ret = DateHelper.DateTimeToUnixTimestamp(DateTime.Now);
string urlLogin = "https://www2.deepl.com/jsonrpc";
var allt = txtCollectFull.Text.ToString();
string myJSONRequest = @"{""jsonrpc"":""2.0"",""method"": ""LMT_handle_jobs"",""params"":{""jobs"":[{""kind"":""default"",""raw_en_sentence"":"""
+ allt + @""",""raw_en_context_before"":[],""raw_en_context_after"":[],""preferred_num_beams"":4,""quality"":""fast""}],""lang"":{""user_preferred_langs"":[""EN"",""DE"",""ZH""],""source_lang_user_selected"":""ZH"",""target_lang"":""EN""},""priority"":-1,""commonJobParams"":{},""apps"":{""usage"":1},""timestamp"":" + ret + @"},""id"":54410005}";
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Add("Referer", "https://www.deepl.com/windows/translator?il=en&windows_app_version=1.12.1");
hc.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
hc.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.5");
hc.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
var stringContent = new StreamContent(GenerateStreamFromString(myJSONRequest));
using (var response = hc.PostAsync(urlLogin, stringContent).Result)
{
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
rtbTranslate.Text = responseBody;
}
}
static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
}
}