zoukankan      html  css  js  c++  java
  • C# dotnetcore2.0结合Selenium搜索网页

    using System;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    namespace ConsoleApp_Selenium
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                ChromeDriver cd = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory.ToString());
                
                cd.Navigate().GoToUrl("http://chart.icaile.com/sd11x5.php");            
                string text = cd.FindElementById("fixedtable").Text;
                
                cd.Quit();
                Console.WriteLine(text);
                Console.Read();
            }
        }
    }
    

      

    nuget安装

    find-package selenium

    install-package Selenium.WebDriver

    install-package Selenium.WebDriver.ChromeDriver

    使用headless chrome这样就没有界面。

    using System;
    using OpenQA.Selenium.Chrome;
    namespace ConsoleApp_Selenium
    {
        class Program
        {
            static void Main(string[] args)
            {
                ChromeOptions op = new ChromeOptions();            
                op.AddArguments("--headless");            
                op.AddArguments("--window-size=1920,1080");            
                ChromeDriver cd = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory.ToString(),op);            
                cd.Navigate().GoToUrl("http://chart.icaile.com/sd11x5.php");            
                string text = cd.FindElementById("fixedtable").Text;            
                cd.Quit();
                Console.WriteLine(text);
                Console.Read();
            }
        }
    }
    

      

    下面是使用PhantomJS

    nuget 安装> install-package Selenium.PhantomJS.WebDriver

    using System;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.PhantomJS;
    namespace ConsoleApp_Selenium
    {
        class Program
        {
            static void Main(string[] args)
            {            
                PhantomJSOptions po = new PhantomJSOptions();            
                po.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0");                
                PhantomJSDriver cd = new PhantomJSDriver(AppDomain.CurrentDomain.BaseDirectory.ToString(), po);
                
                cd.Navigate().GoToUrl("http://chart.icaile.com/sd11x5.php");            
                string text = cd.FindElementById("fixedtable").Text;
                
                cd.Quit();
                Console.WriteLine(text);
                Console.Read();
            }
        }
    }
    

      

  • 相关阅读:
    HTML5中表单的创建
    防冲撞协议原理实验报告
    yii2.0 Activeform表单部分组件使用方法 [ 2.0 版本 ]
    Yii正则验证
    Yii2用Gii自动生成Module+Model+CRUD
    yii2框架安装运行init.bat报错php.exe不是内部或外部命令
    YII2.0安装教程,数据库配置前后台 [ 2.0 版本 ]
    ignore_user_abort函数制定计划任务
    php 常用的系统函数
    php常用字符串处理函数
  • 原文地址:https://www.cnblogs.com/coolyylu/p/8284662.html
Copyright © 2011-2022 走看看