如何使用bs4导航html?

2024-10-01 15:40:56 发布

您现在位置:Python中文网/ 问答频道 /正文

今天下午才开始学python。正在尝试获取的rss源kubuntu.org网站(简单的html)作为练习,但我不知道如何导航html,只打印feedTitle:

#!/usr/bin/python3.5
import bs4 as bs
import urllib.request

site = urllib.request.urlopen('https://kubuntu.org/feed').read()
soup = bs.BeautifulSoup(site, 'lxml')

for title in soup.find_all('item'):
    print(title.text)

编辑:

title添加到find_all行可以满足我的需要,但是仍然有大量的数据也使用title标记。在

^{pr2}$

Tags: orgimportbstitle网站requesthtmlsite

热门问题