首页 > 编程语言 > 详细

Java通过selenium自动化爬去数据

时间:2018-06-19 10:12:03      阅读:268      评论:0      收藏:0      [点我收藏+]

Selenium,作为一个Web应用程序测试的工具。

1,配置selenium的路径和浏览器,我用的是firefox

技术分享图片
webdriver.firefox.bin=D:/tools/firefox/firefox.exe
webdriver.gecko.driver=D:/project/geckodriver.exe
selenium.properties

分别为firefox的安装路径和firefox的驱动路径,这个驱动主要是驱动firefox自动打开,点击按钮等操作。

2,

public class Selenium{
    private static String driver = "";
    private static String fireFox = "";

    static {
        //读取配置文件中关于Selenium的配置
        Properties properties = new Properties();
        InputStream in = Object.class.getResourceAsStream("/selenium.properties");
        try {
            properties.load(in);
            //驱动路径
            driver = properties.getProperty("webdriver.gecko.driver");
            //浏览器路径
            fireFox = properties.getProperty("webdriver.firefox.bin");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
  WebDriver webDriverPC = new FirefoxDriver();

  
public static void main(String[] args) {     String content = webDriverPC.get("http://www.baidu.com")   } }

 

这样就可以得到请求后的HTML,在用

Jsoup处理
Document doc = Jsoup.parse(content);
可得到里面的内容。

 

Java通过selenium自动化爬去数据

原文:https://www.cnblogs.com/zrbchina/p/9197143.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!