【发布时间】:2018-11-07 14:35:19
【问题描述】:
我一直在尝试解析 rss 新闻提要,但我设法获得了大多数字段,但文章的链接和发布日期除外。 这是我的代码:
import bs4
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
import re
#import xml.etree.ElementTree as ET
rss_url="https://news.google.com/news/rss/search/section/q/australia/australia?hl=en-AU&gl=AU&ned=au"
Client=urlopen(rss_url)
xml_page=Client.read()
Client.close()
soup_page=soup(xml_page,"html.parser")
#soup_page=ET.parse(xml_page)
news_list=soup_page.findAll("item")
# Print news title, url and publish date
for news in news_list:
#text=news.text
title=news.title.text
link=news.link.text
pubdate=news.pubDate.text
description=news.description.text
publisher = re.findall('<font color="#6f6f6f">(.*?)</font>', description)
article_link=link
article_info=[title,publisher,link,pubdate]
print(article_info)
我得到了大多数字段,但 pubdate 和 link 除外。知道什么可以帮助吗?非常感谢!
【问题讨论】:
-
发布日期和链接可以获得什么?它们是空白的吗?你有错误吗?
-
我得到了空白返回,没有错误。