【问题标题】:Python: Newspaper Module - Downloading from multiple URLsPython:报纸模块 - 从多个 URL 下载
【发布时间】:2017-04-03 01:39:01
【问题描述】:

我讨厌开始一个新帖子,但我正在努力完成这个问题中描述的确切内容:Python: Newspaper Module - Any way to pool getting articles straight from URLs?

但是,在尝试实施该解决方案时,我收到以下错误:

NameError   Traceback (most recent call last)
<ipython-input-38-2707f1416873> in <module>()
----> 1 sources = [SingleSource(articleURL=u) for u in urls]
      2 
      3 newspaper.news_pool.set(sources)
      4 newspaper.news_pool.join()
      5 

<ipython-input-38-2707f1416873> in <listcomp>(.0)
----> 1 sources = [SingleSource(articleURL=u) for u in urls]
      2 
      3 newspaper.news_pool.set(sources)
      4 newspaper.news_pool.join()
      5 

<ipython-input-37-4949a9e51da5> in __init__(self, articleURL)
      1 class SingleSource(newspaper.Source):
      2     def __init__(self, articleURL):
----> 3         super(StubSource, self).__init__("http://localhost")
      4         self.articles = [newspaper.Article(url=url)]

NameError: name 'StubSource' is not defined

非常感谢您朝着正确的方向前进。

【问题讨论】:

    标签: python python-newspaper


    【解决方案1】:

    链接答案中似乎有错字,因为未定义 StubSource

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

    应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2023-03-28
      相关资源
      最近更新 更多