使用crossrefapi 104错误的全文本关键字搜索

时间:2018-12-17 14:38:13

标签: python python-requests

我正在尝试创建一个脚本,该脚本将使用crossrefapi进行查询,以查找包含大量关键字的所有全文文章。我一直在尝试的脚本如下:

headers = {"CR-Clickthrough-Client-Token": XXXXXXXXXXXXXX, 'X-Rate-Limit-Interval': "1", 'X-Rate-Limit-Limit': "50"}
my_etiquette = Etiquette('melopomene', '0.1', 'n/a', 's.h.young@brighton.ac.uk')  # edit this to be your details
works = Works(etiquette=my_etiquette)
journals = Journals(etiquette=my_etiquette)
s = 1
urls = []
query = works.query("melpomene", "spider", "fern").filter(has_full_text='true',)
print(query)
for item in query:
    res = requests.get(item["link"][0]["URL"], headers=headers)
    filename = "./melpomene/%d.pdf" % s
    with open(filename, "w") as f:
        f.write(res.content)
        s+=1
    time.sleep(5)

但是它返回了以下错误:

<crossref.restful.Works instance at 0x7fa1d6a9fb00>
Traceback (most recent call last):
  File "/home/sandra/git/scrape/DOI_scrape/crossref_scrape_melpomene.py", line 35, in <module>
    main()
  File "/home/sandra/git/scrape/DOI_scrape/crossref_scrape_melpomene.py", line 16, in main
    res = requests.get(item["link"][0]["URL"], headers=headers)
  File "/home/sandra/miniconda3/envs/py27/lib/python2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/sandra/miniconda3/envs/py27/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/sandra/miniconda3/envs/py27/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/sandra/miniconda3/envs/py27/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/sandra/miniconda3/envs/py27/lib/python2.7/site-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))

谁能告诉我我做错了什么以及如何使它起作用?

0 个答案:

没有答案