목적
Java 코드를 통해 Taobao에 자동 로그인을 실현하고 설정을 얻어 설정하여 로그인 정보를 자동으로 작성하여 제출하고 싶습니다. 현재이 코드는 편집자에 의해 테스트되었으며 전달 될 수 있습니다. Taobao가 향후 해당 차단 전략을 가질 지 모르겠습니다.
코드 공유 :
패키지 util; import org.openqa.selenium.by; import org.openqa.selenium.webelement; import org.openqa.selenium.firefox.firefoxdriver; import org.openqa.selenium.firefox.firefox. import org.openqa.selenium.firefox 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 옵션 = 새로운 firefoxoptions (); firefoxprofile profile = new Firefoxprofile (새 파일 ( "c : //users//18431//appdata//roroaming//mozilla//firefox//profiles//efzu2oem.default")); 옵션 .setProfile (프로필); Firefoxdriver 드라이버 = New Firefoxdriver (); driver.get ( "https://login.m.taobao.com/login.htm"); // 다음은 일반 작업을 완전히 시뮬레이션하기 시작하므로 많은 수면 작업이 표시됩니다. WebElement usernameelement = driver.FindElement (by.id ( "username")); // 사용자 시뮬레이션 사용자 이름 입력 상자 usernameelement.click ()을 클릭하십시오. 문자열 username = "1858260144"; // 휴대 전화 번호 string password = "xxxxxxxxxxxx"; // 비밀번호 임의의 rand = new Random (); try {for (int i = 0; i <username.length (); i ++) {thread.sleep (rand.nextint (1000)); // random sleep 0-1 second // 단일 문자 usernameelement.sendkeys ( ""+username.charat (i)); } webElement passwordElement = driver.FindElement (by.id ( "password")); passwordElement.click (); // 사용자 이름을 입력 한 후 0-3 초 동안 무작위로 잠을 자십시오. for (int i = 0; i <password.length (); i ++) {thread.sleep (rand.nextint (1000)); passwordElement.sendkeys ( ""+password.charat (i)); } driver.findElement (by.id ( "btn-submit")). (); } catch (예외 e) {e.printstacktrace (); } try {thread.sleep (300000); } catch (InterruptedException IE) {ie.printstacktrace (); } driver.quit (); }} 요약
로그인을 시뮬레이션하는 것이 아무리 어려운 변화에 관계없이, 인간 작동 습관을 완전히 시뮬레이션하여 크롤러를 구현할 수 있음을 알 수 있습니다. 글쎄, 나는 여러분 모두에게 말할 것입니다. PHP 크롤러 기술은 계속 글쓰기를 계획하지 않습니다. PHP를 사용하여 적합한 일을하는 것이 좋습니다. PHP로 작성된 크롤러 레벨은 너무 낮으며 Python과 Java에게는 더 좋습니다.