LoginSignup
2
5

More than 5 years have passed since last update.

python3でのrss取得

Last updated at Posted at 2018-12-13

python3 feedparserでのrss取得方法

環境

macOS mojave
python 3.7.0(anaconda)
feedparser 5.2.1

feedparserのインストール

condaのupdate
conda update conda
feedparserの有無確認
conda list
なければ
conda install feedparser

anacondaなのでconda。普通ならpip

python code

テストフォルダを作成して mkdir rss-test
pythonのファイル作成 touch rss-test.py

# feedparserのインポート
import feedparser

# URLの取得(今回は朝日新聞デジタルからデジタルジャンルの記事を取得)
RDF_URL = "http://www3.asahi.com/rss/digital.rdf"

degital_news_dic = feedparser.parse(RDF_URL)

print(degital_news_dic.feed.title)

for entry in degital_news_dic.entries:
  title = entry.title
  link = entry.link
  print(link)
  print(title)

実行

python rss-test.py

デジタル - 朝日新聞デジタル
http://www.asahi.com/articles/ASLDD514HLDDUCVL01T.html?ref=rss
今年のグーグル検索ランキング1位は「ワールドカップ」
http://www.asahi.com/articles/ASLDD2W65LDDULFA001.html?ref=rss
グーグルなどの規制強化、政府が新組織 独禁法適用も
http://www.asahi.com/articles/ASLDD3HBMLDDUTIL00M.html?ref=rss
マウント・ゴックス元CEOに懲役10年を求刑
http://www.asahi.com/articles/ASLDC4VLSLDCULFA01L.html?ref=rss
中国機器排除、5Gでも自主対応促す 携帯各社に総務相
http://www.asahi.com/articles/ASLDC5G3XLDCUHBI01P.html?ref=rss
グーグル+、閉鎖時期を前倒し また欠陥発覚
http://www.asahi.com/articles/ASLDD2VZKLDDUHBI00H.html?ref=rss
グーグルの中国再参入、いきなり慎重に「計画はない」
http://www.asahi.com/articles/ASLDD32QWLDDULFA002.html?ref=rss
ソフトバンク通信障害、3060万件に影響 過去最大級
http://www.asahi.com/articles/ASLDC61YLLDCUTIL056.html?ref=rss
ユーチューブに警察無線投稿か 岩手の男性、自ら警察へ
http://www.asahi.com/articles/ASLD76R2WLD7UEHF00N.html?ref=rss
「LINEで支持されたメディア」朝日新聞デジタル大賞
http://www.asahi.com/articles/ASLDB40XNLDBULFA00S.html?ref=rss
菅官房長官「国際ルールに整合」 中国通信2社の排除で
http://www.asahi.com/articles/ASLD73SJ9LD7UTIL008.html?ref=rss
知らないのはあなただけ?動画アプリTikTokって
http://www.asahi.com/articles/ASLD826DFLD8UHBI009.html?ref=rss
トランプ氏、前国務長官を侮辱 「とてつもないバカ」
http://www.asahi.com/articles/ASLD753B4LD7UTIL022.html?ref=rss
東京や新宿、AIが案内します 山手線6駅で実証実験
http://www.asahi.com/articles/ASLD755SLLD7UTIL027.html?ref=rss
スマホつながらないだけなのに…大混乱 どう備える?
http://www.asahi.com/articles/ASLD74RPVLD7ULFA01S.html?ref=rss
携帯参入の楽天・三木谷氏、通信障害に「安定性を追求」
http://www.asahi.com/articles/ASLD7413QLD7UHBI018.html?ref=rss
マリオットの5億人顧客情報流出、背景に中国のスパイか
http://www.asahi.com/articles/ASLD75CJ6LD7UCLV00M.html?ref=rss
海賊版静止画のDL規制を 文化審議会が意見まとめる
http://www.asahi.com/articles/ASLD64HS7LD6UCVL00D.html?ref=rss
ダフ屋行為に罰則、不正転売禁止法成立へ 来年6月施行
http://www.asahi.com/articles/ASLD73SJTLD7PLFA003.html?ref=rss
京セラ稲盛氏の経営塾、解散へ「一代限りで終わらせる」
http://www.asahi.com/articles/ASLCQ4SY1LCQPTIL00N.html?ref=rss
#ニュース4U、始めます SNSで声集め、深掘り取材

こんな感じでRSS取得ができました。

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5