0

Hello i want to build an app with htmlunit for android (Android Studio). If I try to cget the page of youtube this tooks a lot of seconds (over 10). So that is too slow for user experience... other sites are slow too

build.gradle

implementation group: 'org.htmlunit', name: 'htmlunit3-android', version: '3.3.0'

my simple code

   HtmlPage htmlPage;

    try (WebClient webClient = new WebClient()) {

        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);

        htmlPage = webClient.getPage("https://www.youtube.com/");

    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
Dan
  • 1
  • 2

2 Answers2

0

Possible duplicate of: HTMLUnit : super slow execution?

According to the accepted answer of the duplicate question, you can disable Javascript for faster execution

webClient.getOptions().setJavaScriptEnabled(false);//if you don't need js

But if you need JavaScript to be enabled then you may try adding a timeout to request

webClient.setJavaScriptTimeout(30000)
Exitron
  • 17
  • 12
  • thanks, i use HtmlUnit, because Jsoup can't javascript. I want to webscrap some sites. With setting the timeout nothing changes. – Dan Jul 09 '23 at 10:31
  • I am getting a lot of these erros in Logcat. Perhaps here is a problem? But I don't know why: 2023-07-01 14:50:24.006 11570-11579 oid.persistenc com.example.android.persistence I Method exceeds compiler instruction limit: 39878 in int org.htmlunit.cssparser.parser.javacc.CSS3ParserTokenManager.jjMoveNfa_0(int, int) – Dan Jul 09 '23 at 15:30
0

You can also try to do

webClient.getOptions().setDownloadImages(false);
RBRi
  • 2,704
  • 2
  • 11
  • 14