搭建用Selenium模拟chrome浏览器运行环境,为模拟登陆做准备

搭建Selenium自动化环境

1、首先需要下载好对应自己chrome对应的chromedriver

我们在地址栏中输入chrome://version可以查看到更加详细的版本情况。

不仅可以显示浏览器版本,还显示了用户代理,Flash版本,路径和状态信息等


在这里插入图片描述
2、根据自己的chrome下载对应的chromedriver版本(可以通过这里查找)
http://chromedriver.storage.googleapis.com/index.html


在这里插入图片描述


3、下载完毕后,本地指定一个文件夹

扫描二维码关注公众号,回复: 10990415 查看本文章


在这里插入图片描述
4、下载后将chromedriver路径添加到系统环境变量path中
在这里插入图片描述

        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-core</artifactId>
            <version>0.7.3</version>
        </dependency>
        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-extension</artifactId>
            <version>0.7.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/us.codecraft/webmagic-selenium -->
        <!-- Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。        -->
        <dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-selenium</artifactId>
            <version>0.7.3</version>
        </dependency>

通过下列代码测试,在eclipse中运行后调到百度界面

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public  class BaiduSelenium {
      public static void main(String[] args) {

            //C:\Program Files (x86)\Google\Chrome\Application\

            System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
            //
            WebDriver driver=new ChromeDriver();
            driver.get("http://www.baidu.com/");


        }
}

后续会更新通过页面登录的爬虫文章。。。。

猜你喜欢

转载自www.cnblogs.com/asplover/p/12740732.html