对于堆栈溢出上的各种环境,已经讨论了如何登录到Amazon的问题:
里程似乎因所采取的方法而异。例如,截至2013年,一项评论是:
亚马逊已经改变了他们的登录过程,增加了一些CSFR保护,这使得使用cURL登录变得困难。
使用Java时,我也没有机会尝试直接的类卷曲方法并修改OpenId参数:
// https://www.amazon.com/ap/signin?
// _encoding=UTF8&
// openid.assoc_handle=usflex&
// openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&
// openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&
// openid.mode=checkid_setup&
// openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&
// openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&
// openid.pape.max_auth_age=0&
// openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fsign-in.html%3Fie%3DUTF8%26*Version*%3D1%26*entries*%3D0问题:
在这里,使用类似于ruby的机械化样式是否有效?在Java上,哪个是工作机械化的等价物?
发布于 2014-12-01 08:32:23
使用Selenium,请参阅http://www.seleniumhq.org/,可以以一种简单的方式登录。见下面的示例代码
请注意: AmazonUser只是一个帮助类,用于保存登录所需的元素:
示例用法
Amazon amazon = new Amazon();
String html = amazon
.navigate("/gp/css/order-history/ref=oh_aui_menu_open?ie=UTF8&orderFilter=open");亚马逊助手类
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* Amazon handling
* @author wf
*
*/
public class Amazon {
FirefoxDriver driver = new FirefoxDriver();
String root="https://www.amazon.de";
/**
* signIn
* @throws Exception
*/
public void signIn() throws Exception {
// <input type="email" autocapitalize="off" autocorrect="off" tabindex="1" maxlength="128" size="30" value="" name="email" id="ap_email" />
WebElement emailField=driver.findElement(By.id("ap_email"));
// get user and password
AmazonUser auser=AmazonUser.getUser();
emailField.sendKeys(auser.getEmail());
// <input type="password" class="password" onkeypress="displayCapsWarning(event,'ap_caps_warning', this);" tabindex="2" size="20" maxlength="1024" name="password" id="ap_password" />
WebElement passwordField=driver.findElement(By.id("ap_password"));
passwordField.sendKeys(auser.getPassword());
// signInSubmit-input
WebElement signinButton=driver.findElement(By.id("signInSubmit-input"));
signinButton.click();
}
/**
* navigate to the given path
* @param path
* @return
* @throws Exception
*/
public String navigate(String path) throws Exception {
driver.get(root+path);
String html=driver.getPageSource();
if (html.contains("ap_signin_form")) {
signIn();
}
html=driver.getPageSource();
return html;
}
public void close() {
driver.close();
driver.quit();
}
}https://stackoverflow.com/questions/27183439
复制相似问题