Esempio n. 1
0
        public void Run()
        {
            // setup HTML document URL
            var url  = "http://www.sukidog.com/jpierre/strings/basics.htm";
            var name = Path.GetFileName(url);
            // setup XPath query to select fragments
            var xpath = "//p";

            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.GetDocumentFragmentByXPathByUrl(url, xpath, "plain");

            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;
                    string fname   = response.FileName;
                    string outFile = (string.IsNullOrEmpty(fname)) ? $"{Path.GetFileNameWithoutExtension(name)}_fragments.txt" : fname;
                    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));
                    }
                }
            }
        }
Esempio n. 2
0
        public void Test_GetDocumentFragmentByXPathByUrl_1()
        {
            var url   = testUrls[0];
            var xpath = ".//div[@class=\"container\"]";

            var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, xpath, "plain");

            checkGetMethodResponseOkOrNoresult(response, "Document", "_url_xpath_div_class");
        }
Esempio n. 3
0
        public void Test_GetDocumentFragmentByCSSByUrl_2()
        {
            var url    = testUrls[3];
            var csssel = "p";

            var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, csssel, "plain");

            checkGetMethodResponseOkOrNoresult(response, "Document", "_url_xpath_p");
        }
Esempio n. 4
0
        public void Test_GetDocumentFragmentByCSSByUrl_1()
        {
            var url    = testUrls[0];
            var csssel = "div.container";

            var response = HtmlApi.GetDocumentFragmentByXPathByUrl(url, csssel, "plain");

            checkGetMethodResponseOkOrNoresult(response, "Document", "_url_css_div_class");
        }