如何在android中获取url <img src=''>并打开rss feed
<description>
<img src="http://static.ibnlive.in.com/ibnlive/pix/sitepix/03_2010/google_new_630_90x62.jpg" alt="REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected to Hong Kong-based site." title="REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected to Hong Kong-based site." border="0" width="70" height="50" align="left" hspace="5"/>The company joins Google in protesting cyber attacks and censorship in China.
</description>发布于 2014-04-10 17:04:45
如果你想从上面的XML获取一个URL,你可以尝试使用jsoup库:
String input = "<description>\n" +
"<img src=\"http://static.ibnlive.in.com/ibnlive/pix/sitepix/03_2010/google_new_630_90x62.jpg\"" +
" alt=\"REDIRECTED: Google shut its Chinese portal over censorship and visitors were being redirected" +
" to Hong Kong-based site.\" title=\"REDIRECTED: Google shut its Chinese portal" +
" over censorship and visitors were being redirected to Hong Kong-based site.\"" +
" border=\"0\" width=\"70\" height=\"50\" align=\"left\" hspace=\"5\"/>The company" +
" joins Google in protesting cyber attacks and censorship in China.\n" +
"</description>";
Document document = Jsoup.parse(input);
String output = document.select("img").first().attr("src");发布于 2015-07-31 19:06:00
首先,您应该使用RssParser获取描述字符串,然后将该字符串发送到此方法。你不需要去图书馆。当然,首先你应该用‘代替’来匹配你的例子和我的答案,并选择一个特殊的单词,它只存在于你的img url中,代表我的代码中的"equals“,比如你问题中存在的"pix”单词。
private String helperString(String str) {
String[] strings = str.split("'");
for (String string: strings) {
Log.i("STR", "string : " + string);
String[] newString = string.split("/");
for (String a: newString) {
if (a.equals("images")){ //in your question pix or other words
Log.i("URL", "Image Url is : " + string);
return string;
}
}
}
return "";
}https://stackoverflow.com/questions/22982725
复制相似问题