using System;
//添加selenium的引用
using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium;
//添加引用-在程序集中添加System.Drawing
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string baitai_id="006";
string word = "python";
string savepath = "666.html";
var getsource=SearchYahoo(savepath,word, baitai_id);
} public static string SearchYahoo(string SavePath,string word,string baitai_id)
{
ChromeOptions options = new ChromeOptions();
//Set the http proxy value, host and port.
//Set the proxy to the Chrome options
var proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy = "localhost:8080";
proxy.SslProxy = "localhost:8080";
options.Proxy = proxy; options.AddArgument("ignore-certificate-errors");
//options.AddArgument("--headless");
options.AddArgument("--disable-gpu");
string ua = null;
string url = @"https://search.yahoo.co.jp/";
var spua = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25";
var pcua = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"; switch (baitai_id)
{
case "002":
ua = pcua;
url = @"https://www.yahoo.co.jp/";
break;
case "004":
ua = spua;
break;
case "006":
ua = spua;
break;
default:
break;
} options.AddArgument(string.Format("--user-agent={0}", ua));
List<String> tagNmaeList = new List<string>(); ;
var driver = new ChromeDriver(options);
string Source=null;
try
{ //002的换用另外程序
driver.Navigate().GoToUrl(url);
var inputNode = driver.FindElementByXPath(@"//input[@name='p']");
Thread.Sleep(3000);
inputNode.SendKeys(word);
var search = driver.FindElementByXPath(@"//input[@type='submit']");
Thread.Sleep(2000);
search.Click();
Thread.Sleep(5000);
Source = driver.PageSource; }
catch (Exception ex)
{ }
finally
{
// driver.Close(); driver.Quit(); }
System.IO.File.WriteAllText(SavePath, Source, System.Text.Encoding.UTF8);
return Source; }
} }

  

c#使用selenium+Chromedriver参数配置的更多相关文章

  1. ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目

    ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml)   我们都知道在使用WebApi的时候Controller会自动将Action的返回值自动进行各种序列化处理(序列化为 ...

  2. Selenium Java环境配置

    Selenium Java环境配置 上次配置的是C#的环境,今天主要来配置一下Java环境. 首先,对于java环境配置最基础的JDK和JRE 先前我做过配置,这里就不重述了,网上的教程超级多.在基础 ...

  3. Python selenium chrome 环境配置

    Python selenium chrome 环境配置 一.参考文章: 1. 记录一下python easy_install和pip安装地址和方法 http://heipark.iteye.com/b ...

  4. selenium + ChromeDriver 实战系列之启信宝(一)

    之前写了一篇selenium + ChromeDriver的一些入门的知识,这篇博客里面找了启信宝这个网站,简单的进行了一个实战练习.本篇博客的结构如下:       首先会给出一些使用seleniu ...

  5. 转:浅谈UNIX下Apache的MPM及httpd.conf配置文件中相关参数配置

    为什么要并发处理 以Apache为代表的web服务器中,如果不支持并发,则在一个客户端连接的时候,如果该客户端的任务没有处理完,其他连接的客户端将会一直处于等待状态,这事不可想象的,好像没有为什么要不 ...

  6. Spark on Yarn:任务提交参数配置

    当在YARN上运行Spark作业,每个Spark executor作为一个YARN容器运行.Spark可以使得多个Tasks在同一个容器里面运行. 以下参数配置为例子: spark-submit -- ...

  7. Production环境中iptables常用参数配置

    production环境中iptables常用参数配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我相信在实际生产环境中有很多运维的兄弟跟我一样,很少用到iptables的这个 ...

  8. Unity3D安卓打包参数配置与兼容性的关系分析

    前言 在使用Unity3D工程导出安卓安装包的时候,往往会遇到兼容性的问题,针对某些机型,要么无法打开游戏,要么会出现卡机的现象.面对这种情况,我们可以调节相关的参数来提高兼容性. 为了了解在打包时候 ...

  9. 教你如何利用分布式的思想处理集群的参数配置信息——spring的configurer妙用

    引言 最近LZ的技术博文数量直线下降,实在是非常抱歉,之前LZ曾信誓旦旦的说一定要把<深入理解计算机系统>写完,现在看来,LZ似乎是在打自己脸了.尽管LZ内心一直没放弃,但从现状来看,需要 ...

随机推荐

  1. 【bzoj1507】[NOI2003]Editor /【bzoj1269】[AHOI2006]文本编辑器editor Splay

    [bzoj1507][NOI2003]Editor 题目描述 输入 输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作.其中: 为了使输入文件便于阅读,Insert操作的字符串中 ...

  2. Python 源码剖析(四)【LIST对象】

    四.LIST对象 1.PyListObject对象 2.PyListObject的创建与维护 3.PyListObject 对象缓冲池 4.Hack PyListObject 1.PyListObje ...

  3. 转:浅谈Spectral Clustering 谱聚类

    浅谈Spectral Clustering Spectral Clustering,中文通常称为“谱聚类”.由于使用的矩阵的细微差别,谱聚类实际上可以说是一“类”算法. Spectral Cluste ...

  4. Jquery常用正则验证

    常用校验的正则表达式var rulesConfig = { /** * str.replace(/^\s+|\s+$/g, '') 解析: str:要替换的字符串 \s : 表示 space ,空格 ...

  5. BZOJ1568:[JSOI2008]Blue Mary开公司——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1568 李超线段树(不会的话去网上搜吧……). 完. #include<map> #in ...

  6. BZOJ2875 & 洛谷2044:[NOI2012]随机数生成器——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2875 https://www.luogu.org/problemnew/show/P2044 栋栋 ...

  7. BZOJ1053:[HAOI2007]反素数——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1053 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满 ...

  8. 【DP】【Uva437】UVA437 The Tower of Babylon

    传送门 Description Input Output Sample Input Sample Output Case : maximum height = Case : maximum heigh ...

  9. Linux系统上的popen()库函数

    popen可以是系统命令,也可以是自己写的程序a.out. 假如a.out就是打印 “hello world“ 在代码中,想获取什么,都可以通过popen获取. 比如获取ls的信息, 比如获取自己写的 ...

  10. 使用openssl进行文件加密

    #include <iostream> #include <string> #include <stdlib.h> using namespace std; int ...