我想访问 ScopusSearch API 并获取保存在 excel 电子表格中的 1400 篇文章标题列表的 EID。我尝试通过以下代码检索 EID:
import numpy as np
import pandas as pd
from pybliometrics.scopus import ScopusSearch
nan = pd.read_excel(r'C:\Users\Apples\Desktop\test\titles_nan.xlsx', sheet_name='nan')
error_index = {}
for i in range(0,len(nan)):
scopus_title = nan.loc[i ,'Title']
s = ScopusSearch('TITLE("{0}")'.format(scopus_title))
print('TITLE("{0}")'.format(scopus_title))
try:
s = ScopusSearch(scopus_title)
nan.at[i,'EID'] = s.results[0].eid
print(str(i) + ' ' + s.results[0].eid)
except:
nan.loc[i,'EID'] = np.nan
error_index[i] = scopus_title
print(str(i) + 'error' )
但是,我永远无法检索超过 100 个标题(大约)的 EID,因为某些标题会产生太多搜索,这会阻碍整个过程。
因此,我想跳过包含太多搜索的标题并转到下一个标题,同时保留被跳过的标题的记录。
我刚开始使用 Python,所以我不确定如何去做。我有以下顺序:
• 如果标题产生 1 次搜索,则检索 EID 并将其记录在文件“nan”的“EID”列下。
• 如果标题产生超过1 次搜索,则将标题记录在错误索引中,打印'Too many searchs' 并继续进行下一个搜索。
• 如果标题没有产生任何搜索,将标题记录在错误索引中,打印“错误”并继续下一个搜索。
Attempt 1
for i in range(0,len(nan)):
scopus_title = nan.at[i ,'Title']
print('TITLE("{0}")'.format(scopus_title))
s = ScopusSearch('TITLE("{0}")'.format(scopus_title))
print(type(s))
if(s.count()== 1):
nan.at[i,"EID"] = s.results[0].eid
print(str(i) + " " + s.results[0].eid)
elif(s.count()>1):
continue
print(str(i) + " " + "Too many searches")
else:
error_index[i] = scopus_title
print(str(i) + "error")
Attempt 2
for i in range(0,len(nan)):
scopus_title = nan.at[i ,'Title']<br/>
print('TITLE("{0}")'.format(scopus_title))<br/>
s = ScopusSearch('TITLE("{0}")'.format(scopus_title))
if len(s.results)== 1:
nan.at[i,"EID"] = s.results[0].eid
print(str(i) + " " + s.results[0].eid)
elif len(s.results)>1:
continue
print(str(i) + " " + "Too many searches")
else:
continue
print(str(i) + " " + "Error")
我收到错误,指出“ScopusSearch”类型的对象没有 len() /count() 或搜索或本身没有列表。我无法从这里继续。此外,我不确定这是否是正确的做法——根据太多搜索跳过标题。是否有更有效的方法(例如超时——在搜索花费一定时间后跳过标题)。
非常感谢您对此事的任何帮助。谢谢!