简体   繁体   English

使用HtmlUnit时如何“解决” Steam登录?

[英]How to “get around” steam login while using HtmlUnit?

I want to write a java program which can browse webpage associated with steam . 我想编写一个Java程序,可以浏览与steam相关的网页。 The problem is that I don't understand how steam automatically logs in users. 问题是我不了解Steam如何自动登录用户。

I figured these services use some kind of a cookies, but i couldn't find those cookies in chrome cookie manager. 我发现这些服务使用某种cookie,但是在chrome cookie manager中找不到这些cookie。 So even if I write a program which clicks the login button, then goes to the login page there fills it out, the secure page comes up which asks for email confirmation, which I can't and don't want to program. 因此,即使我编写了一个程序,单击“登录”按钮,然后又进入登录页面,将其填写完毕,仍然出现安全页面,要求您进行电子邮件确认,而我不能也不希望进行编程。 These sites are tf2outpost.com and backpack.tf . 这些网站是tf2outpost.comBackpack.tf

Actually, there is an error with the website. 实际上,该网站存在错误。

  1. Go to http://www.tf2outpost.com/ with real browser 使用实际浏览器访问http://www.tf2outpost.com/
  2. Click on 'Sign in through STEAM' 单击“通过STEAM登录”
  3. Check the source of the login page, at line #51 there is: 检查登录页面的来源,在第51行有:
<script language="javascript">
    function Logout()
    {
        $('actionInput').value = 'steam_openid_logout';
        $('openidForm').submit();
    }

    >$J( function() { $J('#steamAccountName').focus() } );

</script>

The issue with >$J , which is incorrect JavaScript and is not tolerated by HtmlUnit. >$J的问题,这是不正确的JavaScript,HtmlUnit不容忍。

To get around this, you can change the response as hinted here . 为了解决这个问题,您可以按照此处的提示更改响应。

So you can have something like: 因此,您可以像以下内容:

try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
    new WebConnectionWrapper(webClient) {

        public WebResponse getResponse(WebRequest request) throws IOException {
            WebResponse response = super.getResponse(request);
            if (request.getUrl().toExternalForm().endsWith("identifier_select")) {
                String content = response.getContentAsString("UTF-8");
                content = content.replace(">$J( function()", "$J( function()");
                WebResponseData data = new WebResponseData(content.getBytes("UTF-8"),
                        response.getStatusCode(), response.getStatusMessage(), response.getResponseHeaders());
                response = new WebResponse(data, request, response.getLoadTime());
            }
            return response;
        }
    };

    HtmlPage page = webClient.getPage("http://www.tf2outpost.com");
    HtmlAnchor a = page.getAnchorByHref("/login");
    page = a.click();
    page.<HtmlInput>getHtmlElementById("steamAccountName").setValueAttribute(username);
    page.<HtmlInput>getHtmlElementById("steamPassword").setValueAttribute(password);
    page = page.<HtmlInput>getHtmlElementById("imageLogin").click();
    webClient.waitForBackgroundJavaScript(5000);
    System.out.println(page.asXml());

Still, here is captcha that came up. 尽管如此,这里还是出现了验证码。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM