Пример #1
0
        static void Main(string[] args)
        {
            // setup the browser
            ScrapingBrowser Browser = new ScrapingBrowser();

            Browser.AllowAutoRedirect = true; // Browser has many settings you can access in setup
            Browser.AllowMetaRedirect = true;
            //go to the home page
            WebPage PageResult = Browser.NavigateToPage(new Uri("http://localhost:51621/"));
            // get first piece of data, the page title
            HtmlNode TitleNode = PageResult.Html.CssSelect(".navbar-brand").First();
            string   PageTitle = TitleNode.InnerText;
            // get a list of data from a table
            List <String> Names = new List <string>();
            var           Table = PageResult.Html.CssSelect("#PersonTable").First();

            foreach (var row in Table.SelectNodes("tbody/tr"))
            {
                foreach (var cell in row.SelectNodes("td[1]"))
                {
                    Names.Add(cell.InnerText);
                }
            }
            // find a form and send back data
            PageWebForm form = PageResult.FindFormById("dataForm");

            // assign values to the form fields
            form["UserName"] = "******";
            form["Gender"]   = "M";
            form.Method      = HttpVerb.Post;
            WebPage resultsPage = form.Submit();
        }
Пример #2
0
        public static WebPage AuthenticationEx(this WebPage webPage, PortalParametersAttribute parameters)
        {
            if (parameters.Login != null)
            {
                var form = webPage.FindFormById(parameters.FormId);
                form[parameters.LoginFieldName]    = parameters.Login;
                form[parameters.PasswordFieldName] = parameters.Password;

                form.Method = HttpVerb.Post;
                return(form.Submit());
            }
            return(webPage);
        }
Пример #3
0
        public static void scrape()
        {
            ScrapingBrowser browser  = new ScrapingBrowser();
            WebPage         homePage = browser.NavigateToPage(new Uri("http://www.bing.com/"));

            PageWebForm form = homePage.FindFormById("sb_form");

            form["q"]   = "scrapysharp";
            form.Method = HttpVerb.Get;
            WebPage resultsPage = form.Submit();

            HtmlNode[] resultsLinks = resultsPage.Html.CssSelect("div.sb_tlst h3 a").ToArray();

            WebPage blogPage = resultsPage.FindLinks(By.Text("romcyber blog | Just another WordPress site")).Single().Click();
        }
Пример #4
0
        // https://www.drf.com/live_odds/winodds/track/GG/USA/11/D

        public void TestBing()
        {
            ScrapingBrowser browser = new ScrapingBrowser();

            //set UseDefaultCookiesParser as false if a website returns invalid cookies format
            //browser.UseDefaultCookiesParser = false;

            WebPage homePage = browser.NavigateToPage(new Uri("http://www.bing.com/"));

            PageWebForm form = homePage.FindFormById("sb_form");

            form["q"]   = "scrapysharp";
            form.Method = HttpVerb.Get;
            WebPage resultsPage = form.Submit();

            HtmlNode[] resultsLinks = resultsPage.Html.CssSelect("div.sb_tlst h3 a").ToArray();

            WebPage blogPage = resultsPage.FindLinks(By.Text("romcyber blog | Just another WordPress site")).Single().Click();
        }
Пример #5
0
        public static ScrapingBrowser GetLoggedBrowser()
        {
            ScrapingBrowser Browser = new ScrapingBrowser();

            Browser.AllowAutoRedirect = true; // Browser has many settings you can access in setup
            Browser.AllowMetaRedirect = true;

            //go to the home page
            WebPage PageResult = Browser.NavigateToPage(new Uri("http://www.pollitika.com"));

            PageWebForm form = PageResult.FindFormById("user-login-form");

            // assign values to the form fields
            form["name"] = "Zvone Radikalni";
            form["pass"] = "******";
            form.Method  = HttpVerb.Post;
            WebPage resultsPage = form.Submit();

            return(Browser);
        }
Пример #6
0
        static void Main(string[] args)
        {
            // setup the browser
            ScrapingBrowser Browser = new ScrapingBrowser();

            Browser.AllowAutoRedirect = true; // Browser has many settings you can access in setup
            Browser.AllowMetaRedirect = true;

            //go to the home page
            WebPage PageResult = Browser.NavigateToPage(new Uri("http://www.pollitika.com"));

            // get first piece of data, the page title
            //HtmlNode TitleNode = PageResult.Html.CssSelect(".navbar-brand").First();
            //string PageTitle = TitleNode.InnerText;

            //// get a list of data from a table
            //List<String> Names = new List<string>();
            //var Table = PageResult.Html.CssSelect("#PersonTable").First();
            //foreach (var row in Table.SelectNodes("tbody/tr"))
            //{
            //    foreach (var cell in row.SelectNodes("td[1]"))
            //    {
            //        Names.Add(cell.InnerText);
            //    }
            //}

            // find a form and send back data
            PageWebForm form = PageResult.FindFormById("user-login-form");

            // assign values to the form fields
            form["name"] = "Zvone Radikalni";
            form["pass"] = "******";
            form.Method  = HttpVerb.Post;
            WebPage resultsPage = form.Submit();

            PageResult = Browser.NavigateToPage(new Uri("http://pollitika.com/hrvatsko-zdravstvo-i-sovjetska-automobilska-industrija"));

            Console.WriteLine(PageResult.Html.InnerHtml);
        }