public void Test_GetHtmlTranslateByURL_en_fr_1() { string sourceUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_02.htm"; Stream stream = TranslationApi.GetTranslateDocumentByUrl(sourceUrl, "en", "fr"); Assert.IsNotNull(stream); Assert.IsTrue(stream.GetType() == typeof(FileStream)); Assert.IsTrue(File.Exists(((FileStream)stream).Name)); }
public void Run() { string srcUrl = "https://stallman.org/sayings.html"; //string srcUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_01.htm"; TranslationApi transApi = new TranslationApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); Stream stream = transApi.GetTranslateDocumentByUrl(srcUrl, SrcLang, ResLang); string strName = null; if (stream != null && stream.GetType() == typeof(FileStream)) { string name = ((FileStream)stream).Name; string outPath = Path.Combine(CommonSettings.OutDirectory, Path.GetFileName(name)); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("File '{0}' downloaded to: {1}", Path.GetFileName(name), outPath)); } } stream.Close(); stream.Dispose(); }