Я получаю фид, анализируя этот URL с < href="https://pypi.python.org/pypi/feedparser" rel="nofollow">парсер фидов, который предоставляется в нижней части публикации.
В приведенном выше URL-адресе есть список zip-файлов по ссылкам на странице. преподаватель (слайд 8) хочет использовать этот код ниже, чтобы извлечь все ссылки (из RSS-канала, я думаю), используя код ниже:
#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
Проблема в том, что сколько бы я ни искал, я не могу найти ссылки для каждого почтового индекса в ленте! Особенно при использовании приведенного выше кода.
Я уверен, что мне чего-то не хватает на картинке...
Вот фид, который я получаю от 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'}