mathlover
mathlover

Reputation: 71

requests from Aminer API

I'm new to python and web-scraping. I need to find all the publications for a specific topic such as "healthcare" with the corresponding authors from Aminer API. Here is the documentation http://doc.aminer.org/en/latest/s/pub/basic.html and my attempt:

import requests
par = {'query': 'healthcare'}
re = requests.get('https://api.aminer.org/api/search/person', params=par)
print(re.text)

which gives me empty result. However, it works when I enter it in "https://www.hurl.it". Your help is appreciated. Thanks.

Upvotes: 2

Views: 336

Answers (1)

damores
damores

Reputation: 2351

Apparently the API has a restriction on User-Agent, so I passed the user agent from my browser (Chrome):

import requests
par = {'query': 'healthcare'}
headers = {'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
re = requests.get('https://api.aminer.org/api/search/person', params=par, headers=headers)
print(re.text)

And it now returns the content. May not be the proper way to call an API but that's a bit out of the API user's hands

Upvotes: 2

Related Questions