【发布时间】:2017-07-01 17:57:28
【问题描述】:
今天下午刚开始学习python。尝试抓取 kubuntu.org(简单 html)的 rss 提要作为练习,但我不知道如何浏览 html 并只打印提要标题:
#!/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 行有点像我想要的,但仍有大量数据也使用标题标签。
#!/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', 'title']):
print(title.text)
【问题讨论】:
标签: python html python-3.x