N
N
Newmo2017-08-18 13:46:24
Java
Newmo, 2017-08-18 13:46:24

How to parse a page when a link is clicked?

Jsoup parses all links and outputs them. By clicking on the link, you need to go to a new Activity to continue parsing. But the shouldOverrideUrlLoading method doesn't work. Here is the code:

protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            //Тут выводим спарсеное

            WebView wv = (WebView) findViewById(R.id.webView);
            wv.setWebViewClient(new WebViewClient() {
                @SuppressWarnings("deprecation")
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    Intent intent = new Intent(MainActivity.this, TrophActivity.class);
                    startActivity(intent);
                    return true;}
            });
            wv.loadData(html,"text/html; charset=utf-8", "UTF-8");
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Newmo, 2017-08-21
@Newmo

Solved a problem. It turns out that JSOUP parsed links without a domain, that is, not absolute. Thus shouldOverrideUrlLoading was not called.
Added to parsing:

for( Element urlElement : hrefs ) {
                    urlElement.attr("href", urlElement.absUrl("href"));
                }<spoiler title=""></spoiler>

Everything worked as it should.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question