【问题标题】:Salesforce not working with HTMLUnitSalesforce 不使用 HTMLUnit
【发布时间】:2023-03-16 19:11:01
【问题描述】:

我正在尝试使用 HTMLUnit 在 Salesforce 上进行一些网络抓取,以获取组织许可信息。如果我尝试通过常规登录/测试 url 访问 Salesforce,它会起作用。但我希望能够使用 /secur/frontdoor.jsp?sid= 方法通过会话 ID 登录。

当我尝试使用它时,Salesforce 抱怨没有启用 javascript。但我在 HTMLUnit 中启用了它。

   java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);

        final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
        HtmlPage page;

        webClient.waitForBackgroundJavaScript(10000);
        webClient.waitForBackgroundJavaScriptStartingBefore(10000);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setRedirectEnabled(true);
        webClient.getOptions().setCssEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setAppletEnabled(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setActiveXNative(true);
        webClient.getOptions().setAppletEnabled(true);

        page = webClient.getPage("https://salesforce--domain/secur/frontdoor.jsp?sid=SessionId");

【问题讨论】:

    标签: java web-scraping salesforce htmlunit


    【解决方案1】:

    想通了。出于某种原因,您没有自动重定向。所以你只需要从第一个 getPage 中获取 URL 并转到新的新 URL。

         java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);
    
        final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
        HtmlPage page;
    
        webClient.waitForBackgroundJavaScript(10000);
        webClient.waitForBackgroundJavaScriptStartingBefore(10000);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setRedirectEnabled(true);
        webClient.getOptions().setCssEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setAppletEnabled(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        webClient.getOptions().setActiveXNative(true);
        webClient.getOptions().setAppletEnabled(true);
    
        page = webClient.getPage("https://salesforce--domain/secur/frontdoor.jsp?sid=SessionId");
    

    page = webClient.getPage(page.getURL());

    【讨论】:

      猜你喜欢
      • 2012-06-17
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多