public void Test_GetDocumentFragmentByCSS_2() { string name = "testpage1.html"; string csssel = "ol>li"; string folder = StorageTestDataPath; var response = HtmlApi.GetDocumentFragmentByCSSSelector(name, csssel, "plain", null, folder); checkGetMethodResponseOkOrNoresult(response, "Document", "_css_ol_li"); }
public void Run() { // setup HTML document name var name = "testpage3_embcss.html"; // setup storage folder path where is the source document var folder = CommonSettings.StorageDataFolder; // setup CSS selector var selector = "ol > li"; // Upload source file to cloud storage var srcPath = Path.Combine(CommonSettings.LocalDataFolder, name); var storagePath = Path.Combine(folder, name).Replace('\\', '/'); if (File.Exists(srcPath)) { SdkBaseRunner.UploadToStorage(storagePath, srcPath); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IDocumentApi docApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); // call the SDK method that returns a query result in the response stream. var response = docApi.GetDocumentFragmentByCSSSelector(name, selector, "plain", null, folder); if (response != null && response.ContentStream != null) { if (response.Status == "NoContent") { Console.WriteLine("Operation succeeded but result is empty"); } else if (response.Status == "OK") { Stream stream = response.ContentStream; var outFile = response.FileName; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } }