Загрузка HTML с использованием Jsoup и рендеринг снова - PullRequest
0 голосов
/ 05 октября 2019

Я пытаюсь извлечь html с веб-сайта и распечатать его на экране с помощью Jsoup, GeckoView

Извлечь HTML-файл можно, но если я попытаюсь отобразить его с помощью geckoview, это не сработает.

Странная вещь ниже

//it's in onCreate method
    val original = GlobalScope.launch {  //coroutine 1
        geckoSession.loadUri(INITIAL_URL) // first i just print a website using geckoview rendering engine, and it works okay 
    }
    val partial = GlobalScope.launch(Dispatchers.Default) { // coroutine 2
        try {
            htmlDocument = Jsoup.connect("https://www.google.com").get() // first i fetch the html document using jsoup
            htmlContentInStringFormat = htmlDocument?.outerHtml() // and i change it to a string object and it works fine
        } catch (e: IOException) {
            e.printStackTrace()
        }
    }
    GlobalScope.launch {
        original.join() // wait until coroutine 1 is done
        partial.join()  // wait until coroutine 2 is done
        geckoSession.loadString(htmlContentInStringFormat!!,"text/plain") 
           /* weird thing is here that if i try to print it as a "text/plain" mime type 
            it works fine, it just prints the plain text of the html string file but 
            if i try to print it using "text/html" mime type, it just prints nothing but white space */
    }

это когда я использовал "text / plain" в качестве второго аргумента метода loadString 1

ant это когда я использовал "text / html", эта напечатанная страница mozila это просто страница, которую я загрузил первым (INITIAL_URL), поэтому метод loadString ничего не печатает в этом случае

2

ссылка на метод loadString здесь

...