抢小米脚本 java,java写自动抢小米手机程序

首先我先说明一下 我这个用的是Selenium(先说下原理 免得大家不懂什么意思 懂得就飞过吧!有的词是copy的 其他人的说法的!)

Selenium RC主要由两部分组成

第一个是Selenium Server

第二个是Client    Libraries

Selenium Server 是用于控制浏览器行为,总的来说,Selenium Server主要包括3个部分: Launcher,Http Proxy,Selenium Core。其中Selenium Core是被Selenium Server嵌入到浏览器页面中的。其实Selenium Core就是一堆JS函数的集合,就是通过这些JS函数,我们才可以实现用程序对浏览器进行操作。

Client Libraries是用来写测试案例时用来控制Selenium Server的库

如要更具体的请观看官网api吧……!

package com.yao;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.ie.InternetExplorerDriver;

public class XiaoMiAutoMain {

public static void main(String[] args) {

String baseUrl = "http://www.xiaomi.com/";

WebDriver driver = new InternetExplorerDriver();

WebElement element = null;

while(true){

try {

driver.get(baseUrl);

//System.out.println(driver.getPageSource());

//Thread.sleep(30 * 1000);

element = driver.findElement(By.className("btnorder"));

element.click();

if(driver.getCurrentUrl()!="http://t.hd.xiaomi.com/index.php?_a=20121119_m22_m1s7&_op=choose"){

break;

}

} catch (Exception ex) {

ex.printStackTrace();

try {

Thread.sleep(2 * 60 * 1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

}

element = driver.findElement(By.className("btnorder"));   其中 btnorder 是预定按钮名称

http://t.hd.xiaomi.com/index.php?_a=20121119_m22_m1s7&_op=choose--> 预定网址

查看页面源代码后会看到以下内容

0818b9ca8b590ca3270a3433284dd417.png

以上两处根据实际情况进行修改(即此应用可以抢购任何东东),在eclipse中直接运行以上代码即可进行自动抢购。

然后需要一个jar包selenium-server-standalone-2.12.0.jar

这个是服务器 cmd进入直接java -jar命令启动即可java -jar 路劲\selenium-server-standalone-2.12.0.jar

0818b9ca8b590ca3270a3433284dd417.png

祝大家抢购愉快!!!

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值