Skip to content

Unable to render specific URL javascript #12

Open
@bhkoo0407

Description

@bhkoo0407

this my code here

======================================================

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            homePage();
        } catch (Exception e) {
            e.printStackTrace();
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void homePage() throws Exception {
        try (final WebClient webClient = new WebClient()) {
            webClient.setAjaxController(new NicelyResynchronizingAjaxController());
            new Thread() {
                public void run() {
                    final HtmlPage page;
                    try {
//                        page = webClient.getPage("http://dx.doi.org/10.1016/j.pgeola.2020.06.005");
                        page = webClient.getPage("http://ghffdg.nksh.beauty");
                        webClient.waitForBackgroundJavaScript(10000);
                        try {
                            Log.i("sleep","10");
                            Thread.sleep(10000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        Log.i("TEST",page.getTitleText());
                        Log.i("TEST",page.asXml());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }.start();


        }
    }
}

======================================================

and this my log

I/sleep: 10
I/TEST: 
I/TEST: <?xml version="1.0" encoding="ISO-8859-1"?>
    <html>
      <head>
        <script>
    //<![CDATA[
    window.location='https://www.efine.go.kr/';
    //]]>
        </script>
      </head>
      <body/>
    </html>

======================================================

I hope Js works and redirects are made.

I've tried these.

  1. webClient.waitForBackgroundJavaScript(10000);

  2. Thread.sleep(10000);

  3. final WebClient webClient = new WebClient(BrowserVersion.CHROME)

If the method is wrong, can I see an example? The official data was difficult to apply over time.

As a result of testing various pages, redirection was not possible only on that page. I don't know if I should look at this as a matter of page. It seems difficult to judge from the normal operation of the PC browser. And it takes longer to load the page than I thought, is there a problem with my code? Or how much time do you have to take?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions