我讨厌开始一个新帖子,但我正在尝试完成这个问题中描述的确切事情: Python:报纸模块 - 有什么方法可以直接从 URL 获取文章吗?
但是,在尝试实施解决方案时,我收到以下错误:
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
将非常感谢朝着正确的方向前进。
看起来像链接答案中的拼写错误,因为未定义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)]