C# dotnetcore2.0结合Selenium搜索网页
2024-08-27 23:14:43
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();
}
}
}
最新文章
- WCF之net.tcp
- backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.
- php : 常用函数
- Linux下如何修改Apache根目录
- [IOS]edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets
- C++基础笔记(三)C++面向对象
- QEMU 使用的镜像文件:qcow2 与 raw
- BZOJ 3983 Takeover Wars 解题报告
- php 多维数组转换
- Twemproxy 分布式集群缓存代理服务器
- php代码审计--sql注入
- python内置函数与匿名函数
- Python全栈-day4-语法基础2
- Linux学习10-CentOS搭建nginx负载均衡环境
- Android开发之ActionBar
- action spring 注入错误,如果检查各项注入都没有错误时,考虑struts 是否配置了namespace(如果你有多个namespace=";/";)
- Python----一些面试题
- Python 函数 -hasattr()
- numpy.random.random &; numpy.ndarray.astype &; numpy.arange
- pL/SQL 创建DBLIKN
热门文章
- [Ramda] Curry and Uncurry Functions with Ramda
- sublime-1 sublime设置到鼠标右键
- 百度消息推送SDK探究(并附上最简推送Demo)
- Role-based access control modeling and auditing system
- 快来看看Google出品的Protocol Buffer,别仅仅会用Json和XML了
- 要求两个异步任务都完成后, 才能回到主线程:dispatch_group_t
- 过滤Filter推断用户是否登录
- java中unicode utf-8以及汉字之间的转换工具类
- Notepad++中删除连续的任意n行
- 打开一个很好的介绍Lucene4 FST文章