selenium 下载百度音乐并验证
package baidu; import java.io.File;
import java.io.IOException; import java.util.List; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions; public class selenium { public static void snapshot(TakesScreenshot drivername, String filename)
{
// this method will take screen shot ,require two parameters ,one is driver name, another is file name File scrFile = drivername.getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
try {
System.out.println("save snapshot path is:E:/"+filename);
FileUtils.copyFile(scrFile, new File("E:\\"+filename));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Can't save screenshot");
e.printStackTrace();
}
finally
{
System.out.println("screen shot finished");
}
} public static void main (String [] args) throws InterruptedException
{ String URL="http://61.135.169.105/";
//avoid Chrome warnning message like "unsupported command-line flag --ignore-certificate-errors. "
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
driver.get(URL);
//max size the browser
driver.manage().window().maximize();
/*
Navigation navigation = driver.navigate();
navigation.to(URL);*/
Thread.sleep(2000);
snapshot((TakesScreenshot)driver,"open_baidu.png");
//WebElement reg=driver.findElement(By.name("tj_reg"));
//reg.click();
// WebElement keyWord = driver.findElement(By.id("kw1")); //find the element
WebElement keyWord = driver.findElement(By.xpath("//input[@id='kw1']"));
keyWord.clear();
//send key words
keyWord.sendKeys("小苹果");
Thread.sleep(3000);
snapshot((TakesScreenshot)driver,"input_keyWord.png"); WebElement submit = driver.findElement(By.id("su1")); System.out.println(submit.getLocation());
submit.click();
//System.out.println(driver.getWindowHandle());
Thread.sleep(5000); WebElement se=driver.findElement(By.xpath("//*[@id=\"2\"]/div[1]/div[2]/table/tbody/tr/td[5]/span/a")) ;
Actions action = new Actions(driver);
action.clickAndHold(se);
action.sendKeys(Keys.DOWN); Thread.sleep(5000); List<WebElement> elementList = driver.findElements(By.tagName("herf"));
for(WebElement e:elementList)
{
System.out.print("-->"+e.getText());
} //se.click(); // System.out.println(driver.getPageSource()); // System.out.println(pageSource);
//WebElement link =driver.findElement(By.xpath(SELENIUM_LINK));
WebElement link =driver.findElement(By.xpath("//*[@id=\"2\"]/div[1]/div[2]/table/tbody/tr/td[5]/span/a"));//By.xpath("//*[@id=\"1\"]/h3/a")); //*[@id="1"]/h3/a
link.click();
Thread.sleep(5000);
driver.switchTo().window(driver.getWindowHandles().toArray(new String[0])[1]);
Thread.sleep(5000);
WebElement down =driver.findElement(By.xpath("//*[@id=\"128\"]"));//<i class="icon btn-icon-download-small"></i> Thread.sleep(5000);
down.click();
snapshot((TakesScreenshot)driver,"down_m.png");
//get page title
System.out.println(driver.getTitle());
Thread.sleep(5000);
WebElement userName=driver.findElement(By.id("TANGRAM__PSP_8__userName"));
WebElement password=driver.findElement(By.id("TANGRAM__PSP_8__password"));
WebElement login=driver.findElement(By.id("TANGRAM__PSP_8__submit"));
Thread.sleep(5000);
userName.sendKeys("QAtest");//your baidu userName
password.sendKeys("mypassword");//your baidu password login.submit();
// navigation.back();
snapshot((TakesScreenshot)driver,"open_bake.png");
System.out.println(driver.getTitle()+"\n"+driver.getCurrentUrl()); Thread.sleep(50000);
File file=new File("C:\\Users\\Young\\Downloads\\小苹果.mp3");
if(file.exists())
{
System.out.println("PASS");
}
else
{
System.out.println("FAIL");
}
driver.quit(); } }
如果出现:unsupported command-line flag --ignore-certificate-errors.
//avoid Chrome warnning message like "unsupported command-line flag --ignore-certificate-errors. "
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
selenium 下载百度音乐并验证的更多相关文章
- [python] 1、python鼠标点击、移动事件应用——写一个自动下载百度音乐的程序
1.问题描述: 最近百度总爱做一些破坏用户信任度的事——文库金币变券.网盘限速,吓得我赶紧想办法把存在百度云音乐中的歌曲下载到本地. http://yinyueyun.baidu.com/ 可问题是云 ...
- 模仿《百度音乐HD》添加到下载框动画
上次听有人说喜欢<百度音乐HD>添加到下载动画 ,我就尝试模仿了下,没想到,今天code4app(地址)也有了这个,但是 这个动画基本相同,我们的思路还是部一样的. 都可以参考 .主要关键 ...
- 百度音乐flac 下载
破解百度音乐白金会员 为了给Play Music上传标签齐全的正版的mp3,本屌翻遍网络苦思冥想.现在终于被我找到了破解之法——破解百度白金会员!破解之后可以直接从百度下载正版授权的320k文件,更可 ...
- 百度音乐API抓取
百度音乐API抓取 前段时间做了一个本地音乐的播放器 github地址,想实现在线播放的功能,于是到处寻找API,很遗憾,不是歌曲不全就是质量不高.在网上发现这么一个APIMRASONG博客,有“获取 ...
- 百度音乐api
百度音乐全接口 会利用使用接口找歌简单又快捷 http://tingapi.ting.baidu.com/v1/restserver/ting 获取方式:GET 参数:format=json或xml& ...
- 如何使用百度音乐搜索接口API
百度有开放音乐搜索的api 比如: http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$ http://b ...
- 百度音乐搜索API介绍
百度音乐搜索API的请求地址如下: [html] view plaincopy http://box.zhangmen.baidu.com/x?op=12&count=1&title= ...
- 如何免费下载付费音乐歌曲,6个网站+8个APP
现在听音乐的软件,QQ音乐,酷狗,网易云等,很多歌曲可以在线听. 但是下载某些歌曲或者在线听高品质无损的都需要付费. 这一期,给大家推荐的是免费下载付费歌曲工具,包括网站跟APP. 网站篇 1.VIP ...
- requests爬取百度音乐
使用requests爬取百度音乐,我想把当前热门歌手的音乐信息爬下来. 首先进行url分析,可以看到: 歌手网页: 薛之谦网页: 可以看到,似乎这些路劲的获取一切都很顺利,然后可以写代码: # -*- ...
随机推荐
- 在 kernel 下打 log。 怪異現象與解決方式。
code battery_log(BAT_LOG_CRTI, "y t: %d \n", (int)my_timer_timeout); battery_log(BAT_LOG_C ...
- 快速排序中的partition函数的枢纽元选择,代码细节,以及其标准实现
很多笔试面试都喜欢考察快排,叫你手写一个也不是啥事.我很早之前就学了这个,对快速排序的过程是很清楚的.但是最近自己尝试手写,发现之前对算法的细节把握不够精准,很多地方甚至只是大脑中的一个映像,而没有理 ...
- 《Javascript高级程序设计》读书笔记(1-3章)
第一章 JavaScript简介 1.1 JavaScript简史 略 1.2 JavaScript实现 虽然 JavaScript 和 ECMAScript 通常都被人们用来表达相同的含义,但 Ja ...
- Netty 系列之 Netty 高性能之道
1. 背景 1.1. 惊人的性能数据 最近一个圈内朋友通过私信告诉我,通过使用 Netty4 + Thrift 压缩二进制编解码技术,他们实现了 10 W TPS(1 K 的复杂 POJO 对象)的跨 ...
- http与https的区别
HTTPhttp是一个应用层协议,由请求和响应构成,是一个标准的客户端服务器模型.http通常承载于TCP之上,有时也承载于TLS或SSL协议层之上,这就是常说的httphttp 无状态协议,同一个客 ...
- webapi-创建项目
- nginx安装与配置
一.在线安装 ubuntu 安装 sudo apt-get install nginx 安装后文件结构为: 配置文件:/etc/nginx ,并且每台虚拟主机已经安排在 /etc/nginx/site ...
- 关于JSF中immediate属性的总结(一)
Purpose The immediate attribute can be used to achieve the following effects: Allow a commandLink or ...
- vs插件ZunKoIDE
→〇,配置: vs →壹,默认背景图路径 C:\Users\{用户名}\AppData\Local\Microsoft\VisualStudio\14.0\Extensions\gqyswd1b.dv ...
- 添加Silverlight应用到HTML
Silverlight是跨浏览器,跨客户平台的浏览器插件,可以应用在Windows,Linux,Mac等平台.作为浏览器插件,Silverlight可以像Flash一样,很方便的嵌套在HTML页面中, ...