我试图从我的拼贴新闻网站获取图像的绝对 URL,但到目前为止还没有成功。我在这个网站http://www.dcu.ie/news/index.shtml工作。正如您从源代码中看到的那样,第一个图像具有绝对 URL,但其余图像只有相对 URL。我已经尝试过 Jsoups 文档中的示例,但无法使其正常工作。这将显示第一张图像,然后显示其余的空框。我会很感激任何可能的帮助。谢谢
public class NewsActivity extends Activity {
WebView mWebView;
String test2 = "<html><body>";
Document docs;
public void main(String... args)
{
try
{
docs = Jsoup.connect("http://www.dcu.ie/news/index.shtml").get();
}
catch (IOException e)
{
e.printStackTrace();
}
Elements imgs = docs.select("img[src$=.jpg]");
for (Element img : imgs)
{
String url = img.toString();
test2 = test2 + " " + url + " ";
}
public void onCreate(Bundle savedInstanceState) {
main();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebViewClient(new NewsClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadData(test2, "text/html", "utf-8");
}
}