selenium + firefox登录空间
在网上看到的大部分都是Python版本的,于是写了个java版本的
环境:
selenium-java 3.9.1
firefox 57.0
geckodriver 0.19.1
firefox与geckodriver下载地址请参考https://blog.csdn.net/cyjs1988/article/details/73039423
代码(注意修改用户名与密码)
public class QZLogin {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver", "D:/browserdriver/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("F:/ff/firefox.exe");
WebDriver driver = new FirefoxDriver(options);
driver.manage().window().maximize();
//超时
try {
driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);
driver.get("https://i.qq.com/");
} catch (Exception e) {
System.out.println("所需元素已出现,停止加载页面");
}finally {
//切换到登录login
driver.switchTo().frame("login_frame");
WebElement switcher_plogin = driver.findElement(By.id("switcher_plogin"));
System.out.println(switcher_plogin.getText());
if(switcher_plogin.isDisplayed()) {
switcher_plogin.click();
}
//用户名
driver.findElement(By.id("u")).clear();
driver.findElement(By.id("u")).sendKeys("******");
//密码
driver.findElement(By.id("p")).clear();
driver.findElement(By.id("p")).sendKeys("******");
//登录
driver.findElement(By.id("login_button")).click();
//等待跳转
Thread.sleep(3000);
//退出frame
driver.switchTo().defaultContent();
System.out.println(driver.getCurrentUrl());
}
// driver.quit();
}
如果你发现程序可以执行,但是速度极慢,多半是因为没有设置超时,导致页面一直在加载,事实上只要你定位的元素出现,就可以停止加载页面了,涉及到iframe的必须切换到iframe,才能定位元素
爬取空间相册:https://www.cnblogs.com/tele-share/p/9610791.html
selenium + firefox登录空间的更多相关文章
- selenium firefox 提取qq空间相册链接
环境: selenium-java 3.9.1 firefox 57.0 geckodriver 0.19.1 1.大概的思路就是模拟用户点击行为,关于滚动条的问题,我是模拟下拉箭头,否则只能每个相册 ...
- 使用Python+Selenium模拟登录QQ空间
使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...
- selenium模拟登录豆瓣和qq空间
selenium模拟登录豆瓣和qq空间今天又重新学习了下selenium,模拟登录豆瓣,发现设置等待时间真的是很重要的一步,不然一直报错:selenium.common.exceptions.NoSu ...
- webcollector + selenium 爬取空间相册图片
package cn.hb.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWr ...
- 使用Selenium+firefox抓取网页指定firefox_profile后的问题
from: https://blog.csdn.net/chufazhe/article/details/51145834 摘要:在使用selenium和firefox抓取网页指定firefox_pr ...
- 4 使用Selenium模拟登录csdn,取出cookie信息,再用requests.session访问个人中心(保持登录状态)
代码: # -*- coding: utf-8 -*- """ Created on Fri Jul 13 16:13:52 2018 @author: a " ...
- selenium 爬取空间说说
package cn.hb.util; import java.io.File; import java.io.FileWriter; import java.io.IOException; impo ...
- Selenium2学习-038-firefox、webdriver版本不对称问题解决:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055
今天有个朋友在群里问,为何脚本运行不通过,其脚本操作步骤简单描述如下: 1.启动火狐浏览器 2.打开百度 3.查询框输入关键字 4.点击按钮[百度一下] 脚本挺简单的,其给出的应用报错信息如下所示: ...
- WebDriver:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
今天尝试最新的webDriver与fireFox搭配: 运行代码时出现如下的问题,但是浏览器却可以打开: org.openqa.selenium.firefox.NotConnectedExcepti ...
随机推荐
- 忍者无敌-实例解说Cocos2d-x瓦片地图
实例比較简单,如图所看到的,地图上有一个忍者精灵,玩家点击他周围的上.下.左.右,他能够向这个方向行走. 当他遇到障碍物后是无法穿越的,障碍物是除了草地以为部分,包含了:树.山.河流等. 忍者实例地图 ...
- Android实践之ScrollView中滑动冲突处理
转载注明出处:http://blog.csdn.net/xiaohanluo/article/details/52130923 1. 前言 在Android开发中,假设是一些简单的布局.都非常easy ...
- Qt产生随机数(两种方法)
第一种方法 #include <QTime> QTime time; time= QTime::currentTime(); qsrand(time.msec()+time.second( ...
- amazeui学习笔记--css(常用组件1)--小徽章Badge
amazeui学习笔记--css(常用组件1)--小徽章Badge 一.总结 1.am-badge:添加am-badge来声明小徽章对象 <span class="am-badge a ...
- TabControl控件重绘
原文地址:http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition 在网上看到重绘TabContr ...
- Altium Designer中敷铜和板子一样大
- (转)windows 下 Java 及 Python 环境变量设置
转自:http://www.cnblogs.com/zhj5chengfeng/archive/2013/01/01/2841253.html http://www.cnblogs.com/qiyes ...
- DC中检查脚本错误
dcprocheck + 要检查的tcl文件
- 《机器学习实战》---第二章 k近邻算法 kNN
下面的代码是在python3中运行, # -*- coding: utf-8 -*- """ Created on Tue Jul 3 17:29:27 2018 @au ...
- java数组10大技巧
0. 声明一个数组(Declare an array) String[] aArray = new String[5]; String[] bArray = {"a"," ...