(java)selenium webdriver学习---实现简单的翻页,将页面内容的标题和标题链接取出
selenium webdriver学习---实现简单的翻页,将页面内容的标题和标题链接取出;
该情况适合能能循环page=1~n,并且每个网页随着循环可以打开的情况,
注意一定是自己拼接的url可以打开,如:http://ask.testfan.cn/articles?page=15,就可以翻到文章分类的第15页;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait; public class YsfTest_20180727{
private static final int ExpectedCondition = 0;
private static final int Boolean = 0;
public static void main(String[] args) throws InterruptedException, IOException{
WebElement search = null;
System.setProperty("webdriver.chrome.driver","C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe");
WebDriver driver = new ChromeDriver();
int pageNum = 15;
int i =1;
while(i <= pageNum){
driver.get("http://ask.testfan.cn/articles?page="+ i);
//窗口最大化
driver.manage().window().maximize();
//将title里面的a标签取出
List<WebElement> ll = driver.findElements(By.cssSelector(".title > a"));
//循环a标签
for(WebElement w:ll){
//将a标签对应的文本取出
System.out.println(w.getText());
//将a标签下href的元素值url取出
System.out.println(w.getAttribute("href"));
}
System.out.println("第"+i+"页面抓取完毕");
i = i + 1;
}
System.out.println("全部抓取完毕");
driver.close();
}
}
该示例抓取的是Testfan软件测试社区的文章标题及链接(只抓了15页),抓取结果以第一页为例:
****************
【工具分享】Jmeter大文件分析利器,比官方快30倍的分析工具
http://ask.testfan.cn/article/1275
Selenium之操作360浏览器
http://ask.testfan.cn/article/1223
Testfan3月接口免费福利课程——秒杀说明
http://ask.testfan.cn/article/1201
Python覆盖率
http://ask.testfan.cn/article/1193
2018职业测试必读书单
http://ask.testfan.cn/article/1191
Selenium——去掉Chrome正受到自动软件测试的控制(Java)
http://ask.testfan.cn/article/1187
【原创】appium-desktop版本配置命令行运行服务(Mac)
http://ask.testfan.cn/article/1186
【原创】appium-desktop版本配置命令行运行服务(windows)
http://ask.testfan.cn/article/1185
Macaca环境配置及样例执行
http://ask.testfan.cn/article/1181
Selenium环境汇总
http://ask.testfan.cn/article/1173
Appium Hybrid混合应用测试——Native切换WebView
http://ask.testfan.cn/article/1169
【Android 】查看被测应用程序package和launchable-activity
http://ask.testfan.cn/article/1168
快捷定位Appium滑动坐标
http://ask.testfan.cn/article/1158
测试用例的设计方法
http://ask.testfan.cn/article/1157
测试工作常用命令
http://ask.testfan.cn/article/1153
jekins安装文档
http://ask.testfan.cn/article/1152
Qtp常见问题解答(百度整理)
http://ask.testfan.cn/article/1151
Testfan10月户外爬山活动报名中
http://ask.testfan.cn/article/1150
APP测试基本流程
http://ask.testfan.cn/article/1149
软件测试面试题:软件测试工具的应用
http://ask.testfan.cn/article/1148
第1页面抓取完毕
******************
本例用到,窗口最大化:driver.manage().window().maximize();
将title里面的a标签取出并放在list里:
List<WebElement> ll = driver.findElements(By.cssSelector(".title > a"));
将a标签对应的文本取出:w.getText();
将a标签下href的元素值url取出:w.getAttribute("href");
(java)selenium webdriver学习---实现简单的翻页,将页面内容的标题和标题链接取出的更多相关文章
- (java)selenium webdriver学习--通过id、name定位,输入内容,搜索,关闭操作、通过tagname查找元素
selenium webdriver学习--通过id.name定位,输入内容,搜索,关闭操作:通过tagname查找元素 打开谷歌浏览器,输入不同的网站,搜索框的定位含有不同元素(有时为id,有时为n ...
- (java)selenium webdriver学习,选择模块,点击下一页,获取当前url
selenium webdriver学习,选择模块,点击下一页,获取当前url 查找下一页有多种方法,这里列举两种: isSelected()函数用于判断是否点击选中,返回Boolean类型 impo ...
- selenium webdriver学习(二)————对浏览器的简单操作(转载JARVI)
selenium webdriver学习(二)————对浏览器的简单操作 博客分类: Selenium-webdriver selenium webdriver对浏览器的简单操作 打开一个测试浏览 ...
- (java)selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待
selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待 本例包括窗口最大化,刷新,切换到指定窗口,后退,前进,获取当前窗口url等操作: import java. ...
- (java)selenium webdriver学习--打开新窗口,并判断新窗口是否与目标窗口一致
描述:selenium webdriver学习--打开新窗口,并判断新窗口是否与目标窗口一致,若一致则切换到该窗口并获取标题 跳出if判断,获取父级标题,并关闭 HTML标签不太明显时,可以用路径表示 ...
- selenium webdriver学习(六)------------如何得到弹出窗口
selenium webdriver学习(六)------------如何得到弹出窗口 在selenium 1.X里面得到弹出窗口是一件比较麻烦的事,特别是新开窗口没有id.name的时候.当时还整理 ...
- selenium webdriver学习(四)------------定位页面元素(转)
selenium webdriver学习(四)------------定位页面元素 博客分类: Selenium-webdriver seleniumwebdriver定位页面元素findElemen ...
- selenium webdriver学习(十)------------如何把一个元素拖放到另一个元素里面(转)
selenium webdriver学习(十)------------如何把一个元素拖放到另一个元素里面 博客分类: Selenium-webdriver 元素拖放drag and drop Q群里 ...
- selenium webdriver学习(九)------------如何操作cookies(转)
selenium webdriver学习(九)------------如何操作cookies 博客分类: Selenium-webdriver Web 测试中我们经常会接触到Cookies,一个C ...
随机推荐
- csp联考T1
本题主要难点在于如何处理dist^2的问题 40分算法 n^2暴力就不必多嘴,直接枚举根节点DFS就行了. 70分算法 对于b=0的情况,我们可以考虑用换根法来计算根节点的变化对总权值带来的影响. 换 ...
- LeetCode 788. 旋转数字(Rotated Digits) 36
788. 旋转数字 788. Rotated Digits 题目描述 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字 ...
- 【剑指offer】面试题 31. 栈的压入、弹出序列
面试题 31. 栈的压入.弹出序列 NowCoder LeetCode 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如 ...
- [十一集训] Day1 (2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018))
A Altruistic Amphibians 原题 题目大意: n只青蛙在高度为d的井中,每只有跳跃距离.重量和高度,每只青蛙可以借助跳到别的青蛙的背上而跳出井,每只青蛙能承受的最大重量是自身重量, ...
- 模块 logging random
模块logging logging模块的主要功能是记录软件调试.操作过程中的各种日志. 默认情况下Python的logging模块将日志打印到了标准输出中,且只显示了大于等于WARNING级别的日志, ...
- Goroutines和线程对比
目录 栈不同 调度不同 GOMAXPROCS Goroutine没有ID号 栈不同 线程:每一个OS线程都有一个固定大小的内存块(一般会是2MB)来做栈,这个栈会用来存储当前正在被调用或挂起(指在调用 ...
- 在Firefox中操作iframe的一个小问题
在做一个 Web 的打印功能时,需要将被打印的文档写到 iframe 的 document 中. <!doctype html> <html lang="en"& ...
- [CodeChef-ANUDTQ] Dynamic Trees and Queries
类似维护括号序列,给每个点建两个点,然后所有操作都能轻松支持了.注意sum和lastans是long long. #include<cstdio> #include<algorith ...
- Spring Spring boot 获取IOC中的bean,ApplicationContext
https://blog.csdn.net/weixin_38361347/article/details/89304414 https://www.jianshu.com/p/9ea13b00b1d ...
- Oracle开放1521端口 telnet不通解决办法
在windosw虚拟机server2012上安装Oracle数据库后,远程连接失败,报 java.sql.SQLException: The Network Adapter could not est ...