downloading files behind javascript button with htmlunit

前端 未结 1 547
情书的邮戳
情书的邮戳 2021-01-07 00:20

I am trying to download something an attachment behind a javascript button with HtmlUnit. Performing other tasks works great (eg. navigating, login). I checked out the attac

1条回答
  •  轮回少年
    2021-01-07 01:04

    Just in case anyone else is wondering: You need to use the AttachmentHandler.

                ScriptResult result = page2.executeJavaScript(buttonJavaScript);
                webClient.waitForBackgroundJavaScript(1000);
    
                if( attachments.size() > 0 )
                {
                    Attachment attachment = attachments.get(0);
    
                    Page attachedPage = attachment.getPage();
                    WebResponse attachmentResponse = attachedPage.getWebResponse();
    
                    String content = attachmentResponse.getContentAsString();
    
                    ... write(content); 
                }
    

    0 讨论(0)
提交回复
热议问题