gpt4 book ai didi

java - 使用 Jsoup 解析 HTML,出现异常

转载 作者:行者123 更新时间:2023-12-01 14:03:41 24 4
gpt4 key购买 nike

我想解析 HTML 页面以获得first.jpg 链接,并将其链接设置为 WebView,以便在应用程序上查看图像。我使用异步任务。它似乎有效,但我在 Try block 上遇到异常。在 LogCat 上,它只是显示 ERROR PARSING ERROR(如您所见,这就是我在 Catch 组中选择的方式)。但没有解释导致异常的原因。代码如下:

@Override
protected String doInBackground(String... params) {
TextView prova = (TextView)findViewById(R.id.searchedName);
Document doc;
try {
doc = Jsoup.connect("[url]http://www.lolking.net/summoner/euw/42997801")
.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
.timeout(3000).get();
String icon = doc.select("img[src$=.jpg]").first().text();
WebView summonerIcon = (WebView)findViewById(R.id.webView1);
summonerIcon.loadUrl(icon);
} catch (Exception e) {
Log.e("ERROR", "PARSING ERROR");
}
return null;

}

最佳答案

String icon = doc.select("img[src$=.jpg]").first().text();

将获取 <img> 中的文本标签。

您的代码应如下所示。

String icon = doc.select("img[src$=.jpg]").first().attr("src");

关于java - 使用 Jsoup 解析 HTML,出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19115447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com