1

我尝试使用 Python2.7 中的学术模块从 Google Scholar 获取特定论文的详细信息。我想收集 1000 篇论文的详细信息,并编写了下面提到的代码。

seq = range(0,1,len(ResearchPaperNames))
for i in seq:
    pub = (next(scholarly.search_pubs_query(ResearchPaperNames[i]))
    print i
    # And further processing to extract data from pub, like author, citation, url

它在 10 到 12 次迭代后给我错误是

Traceback (most recent call last):
  File "C:\Users\Sony\Downloads\Google Scholar Data Extraction.py", line 25, in <module>
    pub = (next(scholarly.search_pubs_query(ResearchPaperNames[i])
StopIteration

我已经浏览了 Stackoverflow 上的几个答案,但我无法修复它。

请帮我修复 StopIteration 错误

4

1 回答 1

3

next将可选的默认值作为第二个参数...

seq = range(0,1,len(ResearchPaperNames))
for i in seq:
    pub = next(scholarly.search_pubs_query(ResearchPaperNames[i]),None)
    print i

将停止我认为的问题......有点......基本上给定的研究论文没有结果,通常简单地在循环内打印也可以作为一般经验法则,迭代超过0..len( array) 来访问它的元素是一种反模式

for paperName in ResearchPaperNames:
    pub = next(scholarly.search_pubs_query(paperName),None)
    if pub is None: 
       print "Error %s not found!"%paperName
    else:
       #process the publication
于 2016-03-20T22:42:40.303 回答