RSS/Python解析单个图像URL

2024-10-01 11:22:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何正确解析xml和rss提要,遇到了一个小问题。我在python中使用feedbarser来解析RSS提要中的特定条目,但是我不知道如何解析content部分中的一个img src。在

以下是我目前所掌握的情况。在

import dirFeedparser.feedparser as feedparser

feedurl = feedparser.parse('http://dustinheroin.chompblog.com/index.php?cat=22&feed=rss2')
statusupdate = feedurl.entries[0].content

print statusupdate

现在,当我打印内容时,我得到的是:

^{pr2}$

从中获得IMG-SRC的最佳方法是什么?谢谢帮忙!在


Tags: importsrcimgas情况条目xmlcontent
2条回答

也许下面的内容会给你一些想法

class Myclass{
    private ArrayList<String> myarray = new ArrayList<>();
    main(){
        //populate the array
    } 
    public ArrayList<String> getList(){
        return myarray;
    }

}

以下是SHG的建议:

public MyStaticClass {
    // from your question is not clear whether you need a static or non static List
    // I will assume a static variable is ok
    // the right-hand member should be enough to synchornize your ArrayList
    public static List<String> myarray = Collections.synchronizedList(new ArrayList<String>());

    public static void main(String[] args) {
        // your stuff (which contains scanner initialization?)

        ArrayList<String> myarray = new ArrayList<>();
        while(scan.hasNextLine()){
            myarray.add(scan.nextLine());
        }
        scan.close();

        // your stuff (which contains thread initialization?)
    }

但是如果你真的需要一个非静态变量

public MyClass {

    private final List<String> myarray;

    public MyClass() {
        // the right-hand member should be enough to synchornize your ArrayList
        myarray = Collections.synchronizedList(new ArrayList<String>());
    }

    public void getArray() {
        return myarray;
    }


    public static void main(String[] args) {
        // your stuff (which contains scanner initialization?)

        Myclass myObj = new MyClass();
        List<String> myObjArray = myObj.getArray();
        while(scan.hasNextLine()){
            myObjArray.add(scan.nextLine());
        }
        scan.close();

        // your stuff (which contains thread initialization?)
    }

有关静态和非静态字段的详细信息,请查看Oracle documentation(基本上,您将需要或不需要MyClass实例来获得myarray访问权限,但您将能够或不能够在JVM中拥有不同的列表)

相关问题 更多 >