您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:报纸模块-有什么方法可以直接从URL获取文章?

Python:报纸模块-有什么方法可以直接从URL获取文章?

我可以通过Source为每个文章URL创建一个来做到这一点。(免责声明:不是python开发人员)

import newspaper

urls = [
  'http://www.baltimorenews.net/index.PHP/sid/234363921',
  'http://www.baltimorenews.net/index.PHP/sid/234323971',
  'http://www.atlantanews.net/index.PHP/sid/234323891',
  'http://www.wpbf.com/news/funeral-held-for-gabby-desouza/33874572',  
]

class SingleSource(newspaper.source):
    def __init__(self, articleURL):
        super(StubSource, self).__init__("http://localhost")
        self.articles = [newspaper.Article(url=url)]

sources = [SingleSource(articleURL=u) for u in urls]

newspaper.news_pool.set(sources)
newspaper.news_pool.join()

for s in sources:
  print s.articles[0].html
python 2022/1/1 18:43:35 有297人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶