Ссылки на извлечение Python

Я получаю фид, анализируя этот 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'}

person ExoticBirdsMerchant    schedule 21.06.2014    source источник
comment
Может быть, ссылки сгенерированы JS или что-то в этом роде?   -  person aIKid    schedule 21.06.2014
comment
JS? что ты конкретно имеешь ввиду   -  person ExoticBirdsMerchant    schedule 21.06.2014
comment
Я не очень хорошо знаком с rss, но разве вы не сможете получить нужную информацию только с помощью HTML?   -  person aIKid    schedule 21.06.2014
comment
Нет, если вы проверите вебинар, это строго формат XML, который мне нужен в этом случае.   -  person ExoticBirdsMerchant    schedule 21.06.2014


Ответы (1)


Что касается меня, вы получаете неполные данные в feed
или вы не добавили остальной код, например downloadfile() со следующего слайда.

Этот код скрывает все сообщения об ошибках

except:
    pass

поэтому измените его на

except Exception as e:
    print( e )

чтобы получить некоторую информацию об ошибке

или удалите try и except pass, чтобы получить полные сообщения об ошибках (обратная трассировка)
и повторите попытку.

person furas    schedule 22.06.2014