[英]Login at Istock using Jsoup
我試圖使用jsoup登錄istockphoto,但始終給我錯誤密碼,用戶和密碼均正確
碼
String user = "myUser";
String pass = "myPass";
Connection doc = Jsoup.connect("https://secure.istockphoto.com/sign-in/");
String token = doc.get().body().getElementById("signInFormtoken").val();
Response res = doc
.data("signInFormtoken",token, "identity", user, "credential", pass, "submit", "Sign In" )
.method(Method.POST)
.execute();
System.out.println(res.body());
Document doc2 = Jsoup.connect("http://www.istockphoto.com/my_uploads.php").cookies(res.cookies()).get();
System.out.println(doc2.title());
表格代碼
<form id="signInForm" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">
<input type="hidden" name="signInFormtoken" value="YToxOntzOjU6InRva2VuIjtzOjMyOiI1M2M5ZmNhZjBhZWZjOTVlZDA3ZDVkNTZlOTg5Y2VjYSI7fQ==" id="signInFormtoken">
<label for="identity" Id="identityLabel" class="optional">Email or Member Name</label>
<input type="text" name="identity" id="identity" value="">
<label for="credential" Id="credentialLabel" class="optional">Password</label>
<input type="password" name="credential" id="credential" value="">
<img id="signInSpinner" class="h mt8" src="https://i.istockimg.com/static/images/loading.gif">
<input type="submit" name="submit" id="sign-in-submit" value="Sign In">
<a id="lost-password-link" href="/istock_lostpassword.php" class="lostPasswordLink">Forgot your password?</a></dl></form>
登錄頁面為https://secure.istockphoto.com/sign-in/
我究竟做錯了什么?
我建議使用Selenium + PhantomJSDriver(Ghostdriver),它用於無GUI的瀏覽器自動化。 使用此工具,您可以輕松瀏覽頁面,選擇元素(可以選擇航班),提交表單並執行一些抓取操作。 還支持Javascript。
您可以在此處瀏覽Selenium文檔。 您將必須下載phantomjs.exe文件。
這里提供了一個很好的PhantomJSDriver教程。
PhantomJSDriver的配置(來自教程):
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C://phantomjs.exe");
caps.setCapability("takesScreenshot", true);
WebDriver driver = new PhantomJSDriver(caps);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.