Created
September 13, 2018 18:34
-
-
Save mpaquette/99022e9e1c8465eb9521c71438eb7013 to your computer and use it in GitHub Desktop.
Dirty Script to count and graph PubMed hits per year for specific search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BeautifulSoup as bs | |
import requests | |
import pylab as pl | |
def countPubmed(searchterm, minyear, maxyear): | |
quer = '%20'.join(searchterm.split(' ')) | |
N_res = [] | |
y = [] | |
for year in range(minyear, maxyear+1): | |
y.append(year) | |
page = requests.get('https://www.ncbi.nlm.nih.gov/pubmed?term=((%22{0}%22%5BDate%20-%20Publication%5D%20%3A%20%22{0}%22%5BDate%20-%20Publication%5D))%20AND%20{1}'.format(str(year), quer)) | |
soup = bs.BeautifulSoup(page.content) | |
q = soup.findAll('meta') | |
t = 'ncbi_resultcount' | |
for el in q: | |
if el.attrs[0][1]==t: | |
v = int(el.attrs[1][1]) | |
N_res.append(v) | |
return y, N_res | |
## CHANGE THIS ################ | |
search = "DTI Brain" | |
minyear = 1995 | |
maxyear = 2017 | |
############################### | |
y, v = countPubmed(search, minyear, maxyear) | |
pl.figure() | |
pl.plot(y, v) | |
pl.title('Pubmed Number of Hits for ({})'.format(search)) | |
pl.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment