How to parse the “” using feedparser?

后端 未结 2 749
眼角桃花
眼角桃花 2021-02-06 13:16

The rss file is shown as below, i want to get the content in section media:group . I check the document of feedparser, but it seems not mention this. How to do

相关标签:
2条回答
  • 2021-02-06 13:56

    feedparser 4.1 as available from PyPi has this bug.

    the solution for me was to get the latest feedparser.py (4.2 pre) from the repository.

    svn checkout http://feedparser.googlecode.com/svn/trunk/ feedparser-readonly
    cd feedparser-readonly
    python setup.py install
    

    now you can access all mrss items

    >>> import feedparser  # the new version!
    >>> d = feedparser.parse(MY_XML_URL)
    >>> for content in d.entries[0].media_content: print content['url']
    

    should do the job for you

    0 讨论(0)
  • 2021-02-06 14:01

    You can parse the feed using

    feed = feedparser.parse(your_feeds_url)
    

    and then access your xml elements using either python's attribute access or dictionary-like access on feed and its subelements. The former method won't work for an element name like media:content, so use the latter method.

    The rest should become clear after studying the examples at http://www.feedparser.org

    0 讨论(0)
提交回复
热议问题