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])
我得到的信息,但我无法搞清楚如何循环它抓住的all_item_tags
各项指标,然后将这些指数的.contents[].contents[]
而无需编写first
second
third
等
编辑:的text.txt
内容 - http://www.dailymail.co.uk/home/index.rss
你能提供text.txt吗? – pregmatch
如何使用all_item_tags中的item_tag? –
它工作ty! item_tag in all_item_tags –