0

URLから画像を取得しようとしていFeedBurnerますが、これを実行できません。

編集:

これはURLです。

画像が<content:encoded>タグ内にあることに気づきました。

また、このURLから画像を取得するのに問題があります。

それから情報を引き出すことができません。

これが私のコードです:

class RSSHandler extends DefaultHandler {

private Post currentPost = new Post();

StringBuffer chars = new StringBuffer();

@Override
public void startElement(String uri, String localName, String qName,
        Attributes atts) {

    chars = new StringBuffer();


    if (localName.equalsIgnoreCase("thumbnail")) {          
        String thumbnail = atts.getValue("url");    
        currentPost.setThumbnail(thumbnail);
    }
}

@Override
public void endElement(String uri, String localName, String qName)
        throws SAXException {

    if (localName.equalsIgnoreCase("title")
            && currentPost.getTitle() == null) {
        currentPost.setTitle(chars.toString());

    }
    String pubd;
    if (localName.equalsIgnoreCase("pubDate")
            && currentPost.getPubDate() == null) {

        currentPost.setPubDate(chars.toString());
        Home.DATE_1.add(chars.toString()); 
    }

    if (localName.equalsIgnoreCase("link") && currentPost.getUrl() == null) {

        currentPost.setUrl(chars.toString());
    }

    if (localName.equalsIgnoreCase("item")) {
        FragmentView.PostList.add(currentPost);

        currentPost = new Post();
        }

}

@Override
public void characters(char ch[], int start, int length) {
    chars.append(new String(ch, start, length));
}

}

このハンドラーを使用して、RSSフィードから情報を取得しています。他のフィードではすべて正常に機能していますが、FeedBurnerURLの場合、画像を取得できないようです。

4

2 に答える 2

0

まず、画像の URL を取得する必要があります

<media:content url="http://thenextweb.com/wp-content/blogs.dir/1/files/2012/11/SC20121102-150432.png" medium="image">
<media:title type="html">SC20121102-150432</media:title>
<media:thumbnail url="http://thenextweb.com/wp-content/blogs.dir/1/files/2012/11/SC20121102-150432-150x150.png" />

画像をビットマップに変換した後、サンプル コード:

public Bitmap getBitmapFromURL(String src) {
    try 
    {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        return BitmapFactory.decodeStream(input);
    } 
    catch (IOException e) 
    {
        //TODO on error
        return null;
    }
}

編集:

最初に HTML ファイルを読み取り、正規表現を使用して IMG タグ内の src URL を取得します

正規表現:

String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";

imgregex 値を使用してビットマップ イメージを取得します。

于 2012-11-02T18:31:54.423 に答える