読者です 読者をやめる 読者になる 読者になる

Googleニュースからリンクを作成

import feedparser
from urllib.parse import parse_qs

from datetime import datetime
#from time import mktime

url= "https://news.google.com/news/feeds?ned=us&ie=UTF-8&oe=UTF-8&q=%E4%BB%8A%E6%B2%BB&output=atom&num=30&hl=ja"

#USER_AGENT変更
feedparser.USER_AGENT = 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko'
fdp = feedparser.parse(url)

#逆順
#fdp.entries.reverse()

for entry in fdp.entries:
    title = entry.title
    
    params = parse_qs(entry.link)
    link = params['url'][0]

    updated = datetime.strptime(entry.updated, '%Y-%m-%dT%H:%M:%SZ')
    #updated = datetime.fromtimestamp(mktime(entry.updated_parsed))
    
    print(title, link, updated)