Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.parse() returns different textContent when calling multiple times in a row #10

Open
GrayTsar opened this issue Aug 9, 2020 · 0 comments

Comments

@GrayTsar
Copy link

GrayTsar commented Aug 9, 2020

Example Code.
Screenshot.

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val webView = findViewById<WebView>(R.id.webView)
        webView?.let {
            it.settings.javaScriptEnabled = true
            it.webViewClient = MyWebViewClient()
        }
        webView.loadUrl("https://en.wikipedia.org/wiki/The_New_York_Times")
    }

    class MyWebViewClient(): WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            super.onPageFinished(view, url)

            view!!.evaluateJavascript("javascript:encodeURI(document.documentElement.outerHTML);") {
                if(!it.isNullOrEmpty()){
                    val txt = URLDecoder.decode(it, "UTF-8")
                    val read = Readability4J(url!!, URLDecoder.decode(it, "UTF-8"))

                    val t1 = read.parse().textContent
                    val t2 = read.parse().textContent
                    val t3 = read.parse().textContent
                    val t4 = read.parse().textContent
                    val t5 = read.parse().articleContent!!.text()
                    val t6 = read.parse().articleContent!!.text()

                    Log.d("DBG", "loaded")
                }
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant