0

I am getting a feed by parsing this URL with feedparser which is supplied at the bottom of the post.

In the URL supplied above there is a list of zip files on links on the page. The tutor (slide 8) wants to use this code below to extract all the links (from the RSS Feed i guess) using the code below:

#Downloading the data - parsing the RSS feed to extract the ZIP file enclosure filename
# Process RSS feed and walk through all items contained
#if you are confused about smthng print(type(obj), repr(obj))
#feed= 'http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-02.xml'
for item in feed.entries:
    print( item[ "summary" ], item[ "title" ], item[ "published" ] )
    try:
        # Identify ZIP file enclosure, if available
        enclosures = [ l for l in item[ "links" ] if l[ "rel" ] == "enclosure" ]
        if ( len( enclosures ) > 0 ):
            # ZIP file enclosure exists, so we can just download the ZIP file
            enclosure = enclosures[0]
            sourceurl = enclosure[ "href" ]
            cik = item[ "edgar_ciknumber" ]
            targetfname = target_dir+cik +' - ' +sourceurl.split('/')[-1]
            retry_counter = 3
            while retry_counter > 0:
                good_read = downloadfile( sourceurl, targetfname )
                if good_read:
                    break
                else:
                    print( "Retrying:", retry_counter )
                    retry_counter -= 1
    except:
        pass

The problem is that no matter how much i search i cannot find the links for each zip in the feed! Especially by using the above code.

I am certain that i am missing something in the picture...

Here is the feed i am getting from feedparser:

{'updated': 'Tue, 25 Jun 2013 22:48:50 EDT', 'published': 'Tue, 25 Jun 2013 22:48:50 EDT', 'subtitle_detail': {'value': 'This is a list all of the filings containing XBRL for 2012-07', 'base': 'http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-07.xml', 'language': None, 'type': 'text/html'}, 'published_parsed': time.struct_time(tm_year=2013, tm_mon=6, tm_mday=26, tm_hour=2, tm_min=48, tm_sec=50, tm_wday=2, tm_yday=177, tm_isdst=0), 'updated_parsed': time.struct_time(tm_year=2013, tm_mon=6, tm_mday=26, tm_hour=2, tm_min=48, tm_sec=50, tm_wday=2, tm_yday=177, tm_isdst=0), 'links': [{'href': 'http://www.sec.gov/spotlight/xbrl/filings-and-feeds.shtml', 'rel': 'alternate', 'type': 'text/html'}, {'href': 'http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-07.xml', 'rel': 'self', 'type': 'application/rss+xml'}], 'title_detail': {'value': 'All XBRL Data Submitted to the SEC for 2012-07', 'base': 'http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-07.xml', 'language': None, 'type': 'text/plain'}, 'subtitle': 'This is a list all of the filings containing XBRL for 2012-07', 'title': 'All XBRL Data Submitted to the SEC for 2012-07', 'language': 'en-us', 'link': 'http://www.sec.gov/spotlight/xbrl/filings-and-feeds.shtml'}
ExoticBirdsMerchant
  • 1,466
  • 8
  • 28
  • 53

1 Answers1

0

As for me you get incomplete data in feed
or you didn't add rest of code like downloadfile() from next slide.

This code hide all error messages

except:
    pass

so change it into

except Exception as e:
    print( e )

to get some error information

or remove try and except pass to get full error messages (traceback)
and try your code again.

furas
  • 134,197
  • 12
  • 106
  • 148