Purpose
I want to realize automatic login on Taobao through JAVA code, and automatically fill in and submit the login information set by obtaining the settings. At present, this code has been tested by the editor and can be passed. I don’t know if Taobao will have a corresponding blocking strategy in the future.
Code sharing:
package util;import org.openqa.selenium.By;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.firefox.FirefoxOptions;import org.openqa.selenium.firefox.FirefoxProfile;import java.io.File;import java.util.Random;public class TestCase2 { public static void main(String[] args) { System.setProperty("webdriver.firefox.bin","C://Program Files//Mozilla Firefox//firefox.exe"); System.setProperty("webdriver.gecko.driver","C://Users//18431//IdeaProjects//SeleniumDemo//bin//geckodriver.exe"); FirefoxOptions options = new FirefoxOptions(); FirefoxProfile profile = new FirefoxProfile(new File("C://Users//18431//AppData//Roaming//Mozilla//Firefox//Profiles//efzu2oem.default")); options.setProfile(profile); FirefoxDriver driver = new FirefoxDriver(); driver.get("https://login.m.taobao.com/login.htm"); //The following starts to fully simulate normal operations, so you will see a lot of sleep operations WebElement usernameElement = driver.findElement(By.id("username")); //Simulate user click on the username input box usernameElement.click(); String username = "18588260144";//Your mobile phone number String password = "xxxxxxxxxxxx";//Your password Random rand = new Random(); try { for (int i = 0; i <username.length() ; i++) { Thread.sleep(rand.nextInt(1000));//Random sleep 0-1 second//Enter a single character usernameElement.sendKeys(""+username.charAt(i)); } WebElement passwordElement = driver.findElement(By.id("password")); passwordElement.click(); //After entering the username, sleep randomly for 0-3 seconds Thread.sleep(rand.nextInt(3000)); for (int i = 0; i <password.length() ; i++) { Thread.sleep(rand.nextInt(1000)); passwordElement.sendKeys(""+password.charAt(i)); } driver.findElement(By.id("btn-submit")).click(); } catch (Exception e){ e.printStackTrace(); } try { Thread.sleep(300000); }catch (InterruptedException ie){ ie.printStackTrace(); } driver.quit(); }} Summarize
It can be seen that no matter how change is, no matter how difficult it is to simulate login, it can completely simulate human operation habits to implement anti-crawlers. Well, I will tell you all. PHP crawler technology is not planned to continue writing. It feels better to use PHP to do things suitable for it. The crawler level written in PHP is too low, and it is better for python and java.