2017-04-16 10 views
0

私はニュースサイトのRSSフィードを解析し、実際の記事への公開日、タイトル、説明、リンク日を引き出そうとしています。これまでのところ、これらのコード行で:bs4.element.tagをルーピング

with open('text.txt', 'r', encoding='utf-8') as f: 
    soup = bs4.BeautifulSoup(f, 'lxml') 
    all_item_tags = soup.find_all('item') 
    first = all_item_tags[0] 
    second = all_item_tags[1] 
    print(first.contents[9].contents[0], first.contents[1].contents[0], first.contents[4], first.contents[5].contents[0]) 
    print(second.contents[9].contents[0], second.contents[1].contents[0], second.contents[4], second.contents[5].contents[0]) 

私はその情報を取得しかし、私はfirstを記述することなく、それはそれらの指標の.contents[].contents[]すべてall_item_tagsのインデックスとをつかむためにどのようにループを考え出すのトラブルを抱えていますsecondthirdなど

編集:text.txtの内容 - コメント欄からhttp://www.dailymail.co.uk/home/index.rss

+0

あなたはtext.txtを提供できますか? – pregmatch

+0

'item_tag in all_item_tags'はどうですか? –

+0

それは仕事だった! item_tag in all_item_tags –

答えて

0

for item_tag in all_item_tags? – t.m.adam