【Selenium】跳转问题
- /**
- * rewrite the get method, adding user defined log</BR>
- * 地址跳转方法,使用WebDriver原生get方法,加入失败重试的次数定义。
- *
- * @param url the url you want to <span id="2_nwp" style="width: auto; height: auto; float: none;"><a target=_blank id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=69829344341ee6cd&k=open&k0=open&kdi0=0&luki=2&n=10&p=baidu&q=v77y4_cpr&rb=0&rs=1&seller_id=1&sid=cde61e3444938269&ssp2=1&stid=0&t=tpclicked3_hc&td=2102575&tu=u2102575&u=http%3A%2F%2Fwww%2Eylzx8%2Ecn%2Fzonghe%2Fopen%2Dsource%2F247951%2Ehtml&urlid=0" target="_blank" mpid="2" style="color: rgb(1, 70, 108); text-decoration: none;"><span style="color: rgb(0, 0, 255); width: auto; height: auto;">open</span></a></span>.
- * @param actionCount retry times when load timeout occuers.
- * @throws RuntimeException
- */
- protected void get(String url, int actionCount) {
- boolean inited = false;
- int index = 0, timeout = 10;
- while (!inited && index < actionCount){
- timeout = (index == actionCount - 1) ? maxLoadTime : 10;//最后一次跳转使用最大的默认超时时间
- inited = navigateAndLoad(url, timeout);
- index ++;
- }
- if (!inited && index == actionCount){//最终跳转失败则抛出运行时异常,退出运行
- throw new RuntimeException("can not get the url [" + url + "] after retry " + actionCount + "times!");
- }
- }
- /**
- * rewrite the get method, adding user defined log</BR>
- * 地址跳转方法,使用WebDriver原生get方法,默认加载超重试【1】次。
- *
- * @param url the url you want to open.
- * @throws RuntimeException
- */
- protected void get(String url) {
- get(url, 2);
- }
- /**
- * judge if the url has navigate and page load completed.</BR>
- * 跳转到指定的URL并且返回是否跳转完整的结果。
- *
- * @param url the url you want to open.
- * @param timeout the timeout for page load in seconds.
- * @return if page load completed.
- */
- private boolean navigateAndLoad(String url, int timeout){
- try {
- driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);
- driver.get(url);
- return true;//跳转并且加载页面成功在返回true
- } catch (TimeoutException e) {
- return false;//超时的情况下返回false
- } catch (Exception e) {
- failValidation();//共用的异常处理方法
- LOG.error(e);//记录错误日志
- throw new RuntimeException(e);//抛出运行时异常,退出运行
- }finally{
- driver.manage().timeouts().pageLoadTimeout(maxLoadTime, TimeUnit.SECONDS);
- }
- }
【Selenium】跳转问题的更多相关文章
- selenium跳过webdriver检测并爬取淘宝我已购买的宝贝数据
简介 上一个博文已经讲述了如何使用selenium跳过webdriver检测并爬取天猫商品数据,所以在此不再详细讲,有需要思路的可以查看另外一篇博文. 源代码 # -*- coding: utf-8 ...
- selenium跳过webdriver检测并爬取天猫商品数据
目录 简介 编写思路 使用教程 演示图片 源代码 @(文章目录) 简介 现在爬取淘宝,天猫商品数据都是需要首先进行登录的.上一节我们已经完成了模拟登录淘宝的步骤,所以在此不详细讲如何模拟登录淘宝.把关 ...
- selenium跳过webdriver检测并模拟登录淘宝
目录 简介 编写思路 使用教程 演示图片 源代码 @(文章目录) 简介 模拟登录淘宝已经不是一件新鲜的事情了,过去我曾经使用get/post方式进行爬虫,同时也加入IP代理池进行跳过检验,但随着大型网 ...
- selenium跳过https的问题
背景: 周六产品给我反馈:支付成功页面后会提示这个,问自动化为什么没有发现这样的问题 第一反应:这个地址肯定被举报了,我也肯定没有设置过安全链接,因为都没有见过这样的网址,如果有问题,应该会直接出错, ...
- Scrapy——5 下载中间件常用函数、scrapy怎么对接selenium、常用的Setting内置设置有哪些
Scrapy——5 下载中间件常用的函数 Scrapy怎样对接selenium 常用的setting内置设置 对接selenium实战 (Downloader Middleware)下载中间件常用函数 ...
- python爬虫10 b站爬取使用 selenium+ phantomJS
但有时候 我们不想要让它打开浏览器去执行 能不能直接在代码里面运行呢 也就是说 有没有一个无形的浏览器呢 恩 phantomJS 就是 它是一个基于 WebKit 的浏览器引擎 可以做到无声无息的操作 ...
- Python+Selenium - windows安全中心的弹窗(账号登录)
当出现如下图所示的 Windows安全中心弹窗,需要输入用户名和密码时 如何用Python+selenium跳过这个登录. 步骤: 1.在注册表中三个位置各添加两个东西:iexplore.exe 和 ...
- python爬虫11 | 这次,将带你爬取b站上的NBA形象大使蔡徐坤和他的球友们
在上一篇中 python爬虫10 | 网站维护人员:真的求求你们了,不要再来爬取了!! 小帅b给大家透露了我们这篇要说的牛逼利器 selenium + phantomjs 如果你看了 python爬虫 ...
- selenium如何跳转到iframe
处理iframe,selenium提供了3中方法: 1.html的frame有id,传入id 2.html的frame有name,传入name 3.先找到iframe的元素,再传入该元素对象 跳出if ...
- selenium+python 浏览器标签页跳转 switch_to_window
浏览器页面跳转方法记录: from selenium import webdriver import time browser = webdriver.Chrome() first_url='http ...
随机推荐
- List遍历时删除遇到的问题
这周在开发中遇到了一个以前没遇到的小Bug,在这里记录下来. List集合,我们平时都经常使用.但是,我在遍历List集合时,调用了List集合的remove方法来删除集合中的元素,简单的代码结构是这 ...
- PHP微信公众平台OAuth2.0网页授权,获取用户信息代码类封装demo(二)
一.这个文件微信授权使用的是OAuth2.0授权的方式.主要有以下简略步骤: 第一步:判断有没有code,有code去第三步,没有code去第二步 第二步:用户同意授权,获取code 第三步:通过co ...
- Ubuntu 16.04安装Wine版的迅雷+QQ(完美方案,终极解决方法)
安装前先备份好系统! 继上一篇安装QQ的方法http://www.cnblogs.com/EasonJim/p/7425978.html,这一篇的QQ采用的是Wine模式安装.完美解决消息记录中文乱码 ...
- C#制作、打包、签名、发布Activex全过程【转】
http://www.cnblogs.com/still-windows7/p/3148623.html 一.前言 最近有这样一个需求,需要在网页上面启动客户端的软件,软件之间的通信.调用,单单依靠H ...
- [Bash] Understand and Use Functions in Bash
n this lesson, we'll go over how bash functions work. Bash functions work like mini bash scripts--yo ...
- java.lang.String中的trim()方法的详细说明(转)
String.Trim()方法到底为我们做了什么,仅仅是去除字符串两端的空格吗? 一直以为Trim()方法就是把字符串两端的空格字符给删去,其实我错了,而且错的比较离谱. 首先我直接反编译String ...
- php自定义错误
function myErrorHandler ( $errno , $errstr , $errfile , $errline ) { if (!( error_reporting () & ...
- 由于扩展配置问题而无法提供您请求的页面...请添加 MIME 映射.--解决方法
http://blog.sina.com.cn/s/blog_4c78de680100quis.html HTTP 错误 404.3 - Not Found由于扩展配置问题而无法提供您请求的页面.如果 ...
- python--网络编程--socket
网络通信标准---网络协议 互联网协议--osi七层协议 五层协议:应用层:应用层.表示层.会话层 传输层:传输层 网络层:网络层 数据链路层:数据链路层 物理层: ...
- AngularJs 在控制器中过滤
<html> <head> <title>Simple app</title> <script src="https://ajax.go ...