我在我的应用中获得了RSS feed。我想从描述标签中获取图像。
所以退出部分
href="http://1.bp.blogspot.com/-cK4XpGZFqrw/TlzZVDN29EI/AAAAAAAAIP4/HIPTiLxMHB8/s1600/empoou.jpg"
这
<description><p><a href="http://feedads.g.doubleclick.net/~a/b4nArh9wvGYEh4cdSiHD3-Kk4CM/0/da"><img src="http://feedads.g.doubleclick.net/~a/b4nArh9wvGYEh4cdSiHD3-Kk4CM/0/di" border="0" ismap="true"></img></a><br/><ahref="http://feedads.g.doubleclick.net/~a/b4nArh9wvGYEh4cdSiHD3-k4CM/1/da"><imgsrc="http://feedads.g.doubleclick.net/~a/b4nArh9wvGYEh4cdSiHD3-Kk4CM/1/di" border="0" ismap="true"></img></a></p><a href="http://1.bp.blogspot.com/-cK4XpGZFqrw/TlzZVDN29EI/AAAAAAAAIP4/HIPTiLxMHB8/s1600/empoou.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 180px;" .............
我正在使用sax解析器来加载RSS。有什么帮助来获得图像?感谢
答案 0 :(得分:1)
然后,如果您有图像的URL,请看这个例子:
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class Example1 extends Activity{
EditText inputUrl;
OnClickListener getImageBtnOnClick = new OnClickListener() {
public void onClick(View view) {
Context context = view.getContext();
Editable ed = inputUrl.getText();
Drawable image = ImageOperations(context,ed.toString(),"image.jpg");
ImageView imgView = new ImageView(context);
imgView = (ImageView)findViewById(R.id.image1);
imgView.setImageDrawable(image);
}
};
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
inputUrl = ((EditText)findViewById(R.id.imageUrl));
inputUrl.setSingleLine();
inputUrl.setTextSize(11);
Button getImageButton = (Button)findViewById(R.id.getImageButton);
getImageButton.setOnClickListener(getImageBtnOnClick);
}
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
}
并在那里完整的教程: http://asantoso.wordpress.com/2008/03/07/download-and-view-image-from-the-web/
答案 1 :(得分:1)
使用此jsoup lib获取HTML元素属性值
的值首先,您需要执行xml解析,然后
1, 2, 3, 4, 5
如果有多个img元素,doc.select()返回多个Element对象,如果你想获得img元素,那么第一个索引然后使用下面的代码,
AAA, BBB, CCC, DDD, EEE