首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >远程登录到Amazon

远程登录到Amazon
EN

Stack Overflow用户
提问于 2014-11-28 06:54:46
回答 1查看 1.3K关注 0票数 0

对于堆栈溢出上的各种环境,已经讨论了如何登录到Amazon的问题:

里程似乎因所采取的方法而异。例如,截至2013年,一项评论是:

亚马逊已经改变了他们的登录过程,增加了一些CSFR保护,这使得使用cURL登录变得困难。

使用Java时,我也没有机会尝试直接的类卷曲方法并修改OpenId参数:

代码语言:javascript
复制
// 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上,哪个是工作机械化的等价物?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-01 08:32:23

使用Selenium,请参阅http://www.seleniumhq.org/,可以以一种简单的方式登录。见下面的示例代码

请注意: AmazonUser只是一个帮助类,用于保存登录所需的元素:

  • 电子邮件
  • 密码

示例用法

代码语言:javascript
复制
Amazon amazon = new Amazon();
String html = amazon
  .navigate("/gp/css/order-history/ref=oh_aui_menu_open?ie=UTF8&orderFilter=open");

亚马逊助手类

代码语言:javascript
复制
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();      
  }


}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27183439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档