-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_wos_export.py
231 lines (181 loc) · 9.35 KB
/
1_wos_export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
# coding: utf-8
# # Automating exports using Web of Science
#
# Notebook used for the study presented at the EAHIL 2022 conference
#
# * Title: Computational assistance in the analysis of cited references in biomedical literature: a case study from two institutions.
#
# * Authors:
# * Teresa Lee, Knowledge Manager, International Agency for Research on Cancer (IARC/WHO) leet@iarc.fr
# * Pablo Iriarte, IT Coordinator, Library of the University of Geneva Pablo.Iriarte@unige.ch
# * Floriane Muller, Librarian (Medical Library), Library of the University of Geneva Floriane.Muller@unige.ch
# * Ramon Cierco Jimenez, Doctoral Student, International Agency for Research on Cancer (IARC/WHO) CiercoR@students.iarc.fr
#
#
# ## Required python libraries
# 1. selenium
# 1. os
# 1. time
# 1. datetime
#
#
# ## Export steps
# 1. Launch WoS advanced search, accept cookies and close tutorial pop-ups
# 1. Exclude editions not needed (in our case we remove SSCI and AHCI edition keeping only SCI edition and Emerging sources)
# 1. Search by affiliation name\*, range of publication years (in our case "2001-2020") and categories\**
# 1. Export results by groups of articles (max. 500 at a time) with the cited refs
# 1. Rename the file with the range of records
#
# \* using the name given by WoS on the affiliation list (in our case "University of Geneva")
# \** using a choice of subjetcs from the list available on Clarivate Website: https://support.clarivate.com/ScientificandAcademicResearch/s/article/Web-of-Science-List-of-Subject-Classifications-for-All-Databases?language=en_US
#
# In[2]:
import os
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.firefox.options import Options
import time
import datetime
# search criteria
affiliation = 'University of Geneva'
publication_years = '2001-2020'
categories = '"Life Sciences & Biomedicine - Other Topics" OR "Allergy" OR "Anatomy & Morphology" OR "Anesthesiology" OR "Biochemistry & Molecular Biology" OR "Biophysics" OR "Biotechnology & Applied Microbiology" OR "Cardiovascular System & Cardiology" OR "Cell Biology" OR "Critical Care Medicine" OR "Dentistry, Oral Surgery & Medicine" OR "Dermatology" OR "Developmental Biology" OR "Emergency Medicine" OR "Endocrinology & Metabolism" OR "Evolutionary Biology" OR "Gastroenterology & Hepatology" OR "General & Internal Medicine" OR "Genetics & Heredity" OR "Geriatrics & Gerontology" OR "Health Care Sciences & Services" OR "Hematology" OR "Immunology" OR "Infectious Diseases" OR "Integrative & Complementary Medicine" OR "Legal Medicine" OR "Mathematical & Computational Biology" OR "Medical Ethics" OR "Medical Informatics" OR "Medical Laboratory Technology" OR "Microbiology" OR "Neurosciences & Neurology" OR "Nursing" OR "Nutrition & Dietetics" OR "Obstetrics & Gynecology" OR "Oncology" OR "Ophthalmology" OR "Orthopedics" OR "Otorhinolaryngology" OR "Parasitology" OR "Pathology" OR "Pediatrics" OR "Pharmacology & Pharmacy" OR "Physiology" OR "Psychiatry" OR "Public, Environmental & Occupational Health" OR "Radiology, Nuclear Medicine & Medical Imaging" OR "Rehabilitation" OR "Reproductive Biology" OR "Research & Experimental Medicine" OR "Respiratory System" OR "Rheumatology" OR "Sport Sciences" OR "Substance Abuse" OR "Surgery" OR "Toxicology" OR "Transplantation" OR "Tropical Medicine" OR "Urology & Nephrology" OR "Veterinary Sciences" OR "Virology"'
# WoS editions to exclude (yes|no)
exclude_ssci = 'yes'
exclude_ahci = 'yes'
# downloads parameters
download_dir = 'D:\\switchdrive\\EAHIL\\EAHIL_2022\\code\\data\\sources'
# number of records to be downloaded at a time (max. 500)
download_records = 500
# in case of interruption of downloads define the files to skip
skip_files = 0
# URL for WoS advanced search
wos_url = 'https://www.webofscience.com/wos/woscc/advanced-search'
# construct WoS query
query = 'OG=(' + affiliation + ')'
if (publication_years != '') :
query = query + ' AND PY=(' + publication_years + ')'
if (categories != '') :
query = query + ' AND WC=(' + categories + ')'
# options for selenium browser and downloads
options = Options()
options.set_preference('browser.download.folderList',2)
options.set_preference('browser.download.manager.showWhenStarting', False)
options.set_preference('browser.download.dir', download_dir)
options.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream,text/csv,application/csv,text/plain')
driver = webdriver.Firefox(executable_path = r'geckodriver\geckodriver.exe', options = options)
driver.maximize_window()
# In[3]:
# go to WoS search page
driver.get(wos_url)
# accept cookies
time.sleep(1)
driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]').click()
# close tutorial windows
time.sleep(1)
driver.find_element_by_xpath('//*[@class="bb-button _pendo-button-primaryButton _pendo-button"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@class="bb-button _pendo-button-secondaryButton _pendo-button"]').click()
# exclude SSCI
if (exclude_ssci == 'yes'):
# select WoS editions
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="selectEdition Science Citation Index Expanded<br/>(SCI-EXPANDED)--1900-present"]').click()
# unselect SSCI
time.sleep(1)
driver.find_element_by_xpath('//*[@title="Social Sciences Citation Index<br/>(SSCI)--1956-present"]').click()
# exclude AHCI
if (exclude_ahci == 'yes'):
# select WoS editions
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="selectEdition Science Citation Index Expanded<br/>(SCI-EXPANDED)--1900-present"]').click()
# unselect AHCI
time.sleep(1)
driver.find_element_by_xpath('//*[@title="Arts & Humanities Citation Index<br/>(AHCI)--1975-present"]').click()
# input search query
time.sleep(1)
driver.find_element_by_id('advancedSearchInputArea').send_keys(query)
# send query
time.sleep(1)
driver.find_element_by_xpath('//*[@data-ta="run-search"]').click()
# extract the number of results
time.sleep(3)
results = driver.find_element_by_xpath('//*[@data-ta-search-info-count]').get_attribute('data-ta-search-info-count')
# count files needed
results = int(results)
if (results <= download_records):
files = 1
else :
files = int(results / download_records) + 1
# In[3]:
# export results by sets of 500 records
print ('Results: ' + str(results))
print ('Files to export: ' + str(files))
print('Start time: ' + str(datetime.datetime.now()))
print('-----------------------------------')
print(' ')
for i in range(files):
if (skip_files > 0 and i < skip_files):
continue
time.sleep(1)
file_start = i * download_records + 1
if (i + 1 == files):
file_end = results
else :
file_end = i * download_records + download_records
filename = 'savedrecs_' + str(file_start).zfill(10) + '_' + str(file_end).zfill(10) + '.txt'
print ('File ' + str(i + 1) + ' of ' + str(files) + ' "' + filename + '" from ' + str(file_start) + ' to ' + str(file_end), end='')
# downloads loop
download_successful = False
while not download_successful:
# click on export button
time.sleep(1)
driver.find_element_by_xpath('//*[@class="mat-focus-indicator mat-menu-trigger cdx-but-md cdx-but-white-background margin-right-10--reversible mat-button mat-stroked-button mat-button-base mat-primary"]').click()
# click on export button
time.sleep(2)
driver.find_element_by_xpath('//*[@id="exportToTabWinButton"]').click()
# click on records range
time.sleep(1)
driver.find_element_by_xpath('//*[@for="radio3-input"]').click()
# empty from range
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="Input starting record range"]').clear()
# put from range
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="Input starting record range"]').send_keys(str(file_start))
# empty to range
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="Input ending record range"]').clear()
# put to range
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label="Input ending record range"]').send_keys(str(file_end))
# select record content dropdown
time.sleep(1)
driver.find_element_by_xpath('//*[@aria-label=" Author, Title, Source"]').click()
# select record content fields
time.sleep(1)
driver.find_element_by_xpath('//*[@title="Full Record and Cited References"]').click()
# run export
time.sleep(1)
driver.find_element_by_xpath('//*[@class="mat-focus-indicator cdx-but-md mat-stroked-button mat-button-base mat-primary"]').click()
# wait for download to finish
print(' - Waiting for download ', end='')
while not any([filename == 'savedrecs.txt' for filename in os.listdir('data/sources/')]):
time.sleep(2)
print('.', end='')
print(' done!')
# test file size
time.sleep(1)
filesize = os.path.getsize('data/sources/savedrecs.txt')
if (filesize > 0):
download_successful = True
else :
os.remove('data/sources/savedrecs.txt')
# rename file
time.sleep(1)
os.rename('data/sources/savedrecs.txt', 'data/sources/' + filename)
print(' ')
print('-----------------------------------')
print('End time: ' + str(datetime.datetime.now()))
# In[ ]: