【爬虫】Selenium+chrome
一、下载对应chrome版本的webdriver
https://npm.taobao.org/mirrors/chromedriver
二、pom
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
三、初始化selenium
System.setProperty("webdriver.chrome.driver",driverPath+"/chromedriver.exe");
ChromeOptions chromeOptions=new ChromeOptions();
//设置 chrome 的无头模式
chromeOptions.setHeadless(Boolean.TRUE); //TRUE为无头模式
chromeOptions.addArguments("--disable-gpu"//禁止使用gpu
,"--blink-settings=imagesEnabled=false"//禁止加载图片
,"--user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"//使用user-agent
);
chromeOptions.setCapability("enableVideo", false);//禁止播放视频
//启动一个 chrome 实例
webDriver = new ChromeDriver(chromeOptions);
webDriver.manage().timeouts().setScriptTimeout(15,TimeUnit.SECONDS);//设置15秒超时时间
//webDriver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
webDriver.manage().timeouts().pageLoadTimeout(15,TimeUnit.SECONDS);
四、访问URL,返回页面dom
try {
webDriver.get(url);
}catch (TimeoutException e){
((JavascriptExecutor)webDriver).executeScript("window.stop()");
}
return webDriver.getPageSource();
五、输入框填值
WebDriverWait wait1 = new WebDriverWait(seleniumUtil.getWebDriver(), 10);
WebElement element1=wait1.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[name=username]")));
element1.click();
element1.sendKeys(userName);
【爬虫】Selenium+chrome的更多相关文章
- python爬虫——selenium+chrome使用代理
先看下本文中的知识点: python selenium库安装 chrome webdirver的下载安装 selenium+chrome使用代理 进阶学习 搭建开发环境: selenium库 chro ...
- 小白学爬虫-在无GUI的CentOS上使用Selenium+Chrome
爬虫代理IP由芝麻HTTP服务供应商提供各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题! 但是另一个▄█▀█ ...
- chrome浏览器爬虫WebDriverException解决采用python + selenium + chrome + headless模式
WebDriverException: Message: unknown error: Chrome failed to start: crashed 第一种:如果出现下面情况: chrome浏览器有 ...
- 芝麻HTTP:爬虫之设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分 ...
- 小白学爬虫-设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分 ...
- [Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍
前三篇文章介绍了安装过程和通过Selenium实现访问Firefox浏览器并自动搜索"Eastmount"关键字及截图的功能.而这篇文章主要简单介绍如何实现自动登录163邮箱,同时 ...
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...
- python爬虫---selenium库的用法
python爬虫---selenium库的用法 selenium是一个自动化测试工具,支持Firefox,Chrome等众多浏览器 在爬虫中的应用主要是用来解决JS渲染的问题. 1.使用前需要安装这个 ...
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍
这篇文章主要Selenium+Python自动测试或爬虫中的常见定位方法.鼠标操作.键盘操作介绍,希望该篇基础性文章对你有所帮助,如果有错误或不足之处,请海涵~同时CSDN总是屏蔽这篇文章,再加上最近 ...
随机推荐
- 前端HTTP缓存
Web 缓存大致可以分为:数据库缓存.服务器端缓存(代理服务器缓存.CDN 缓存).浏览器缓存.其中前端比较关心的是浏览器缓存,包括今天要说的HTTP缓存和前面说过的cookie.localStora ...
- 手写CSS+js实现radio单选按钮
有的时候我们需要用长得漂亮一点的单选按钮,那么,就要抛弃原有的自己来写,下面就是我实现的 <div class="radio"><span class=" ...
- android读取xml
/*** 从config.xml中获取版本信息以及应用id* * @param urlPath* @return* @throws Exception*/public List getUpdateIn ...
- kali的网络IP设置
进入配置文件,配置IP leafpad /etc/network/interfaces.conf 写入如下格式的内容: /etc/network/interfaces # This file desc ...
- 11年Macbook Air 安装win10 经验
11年macbook air安装win10折腾了好久,安装成功经验记录下. 1.使用BootCamp v6.0.6133 2.启动时U盘里面有两个引导Window和EFI,选择Windows启动.EF ...
- str_pad()函数
str_pad - 使用另一个字符串填充字符串为指定长度 <?php $str = 'hello world '; echo str_pad($str,20,'·'); ?> 结果 ...
- python 浮点运算
print(format(float(a)/float(b),'.2f'))
- BBED ORA-00600: internal error code, arguments: [16703], [1403], [20], [], [], [], [], [], [], [], [], []
BBED模拟并修复 删除:$ORACLE_HOME/rdbms/admin/prvtsupp.plb SQL> alter database open;alter database open*E ...
- 职位-CIO:CIO
ylbtech-职位-CIO:CIO 首席信息官(又称CIO,是Chief Information Officer的缩写)中文意思是首席信息官或信息主管,是负责一个公司信息技术和系统所有领域的高级官员 ...
- 015-elasticsearch5.4.3【五】-搜索API【四】Joining 多文档查询、GEO查询、moreLikeThisQuery、script脚本查询、span跨度查询
一.Joining 多文档查询 joining query 像Elasticsearch这样的分布式系统中执行完整的SQL样式连接非常昂贵.相反,Elasticsearch提供两种形式的连接,旨在水平 ...