|
a |
|
b/notebooks/scraping.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "code", |
|
|
5 |
"execution_count": 1, |
|
|
6 |
"metadata": {}, |
|
|
7 |
"outputs": [], |
|
|
8 |
"source": [ |
|
|
9 |
"from selenium import webdriver\n", |
|
|
10 |
"from selenium.webdriver.support.ui import Select\n", |
|
|
11 |
"from selenium.webdriver.common.by import By\n", |
|
|
12 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
13 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
14 |
"from selenium.common.exceptions import TimeoutException\n", |
|
|
15 |
"import time" |
|
|
16 |
] |
|
|
17 |
}, |
|
|
18 |
{ |
|
|
19 |
"cell_type": "markdown", |
|
|
20 |
"metadata": {}, |
|
|
21 |
"source": [ |
|
|
22 |
"//*[@id=\"adv-check-status\"]/div/div[2]" |
|
|
23 |
] |
|
|
24 |
}, |
|
|
25 |
{ |
|
|
26 |
"cell_type": "code", |
|
|
27 |
"execution_count": 9, |
|
|
28 |
"metadata": {}, |
|
|
29 |
"outputs": [ |
|
|
30 |
{ |
|
|
31 |
"name": "stdout", |
|
|
32 |
"output_type": "stream", |
|
|
33 |
"text": [ |
|
|
34 |
"Radio button for 'Recruiting and not yet recruiting studies' is detected and visible: True\n" |
|
|
35 |
] |
|
|
36 |
} |
|
|
37 |
], |
|
|
38 |
"source": [ |
|
|
39 |
"driver = webdriver.Chrome()\n", |
|
|
40 |
"driver.set_window_size(1120, 1000)\n", |
|
|
41 |
"driver.get(\"https://clinicaltrials.gov\")\n", |
|
|
42 |
"\n", |
|
|
43 |
"try:\n", |
|
|
44 |
" # Wait for the radio group container to be visible\n", |
|
|
45 |
" WebDriverWait(driver, 20).until(\n", |
|
|
46 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[2]/ctg-search-filters-form/div[2]'))\n", |
|
|
47 |
" )\n", |
|
|
48 |
"\n", |
|
|
49 |
" # Option 1: Wait for the radio button using ID\n", |
|
|
50 |
" recruiting_radio_button = WebDriverWait(driver, 20).until(\n", |
|
|
51 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div/div[2]'))\n", |
|
|
52 |
" )\n", |
|
|
53 |
"\n", |
|
|
54 |
" # Option 2: Wait for the label and locate the radio button\n", |
|
|
55 |
" # recruiting_radio_label = WebDriverWait(driver, 20).until(\n", |
|
|
56 |
" # EC.element_to_be_clickable((By.XPATH, \"//label[@for='adv-radio-status1']\"))\n", |
|
|
57 |
" # )\n", |
|
|
58 |
" # recruiting_radio_button = driver.find_element(By.XPATH, \"//input[@id='adv-radio-status1']\")\n", |
|
|
59 |
"\n", |
|
|
60 |
" # Print if the radio button is displayed\n", |
|
|
61 |
" print(\"Radio button for 'Recruiting and not yet recruiting studies' is detected and visible:\", recruiting_radio_button.is_displayed())\n", |
|
|
62 |
" \n", |
|
|
63 |
" # Scroll the page to bring the element into view before clicking\n", |
|
|
64 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", recruiting_radio_button)\n", |
|
|
65 |
"\n", |
|
|
66 |
" # Click the button after scrolling to it\n", |
|
|
67 |
" recruiting_radio_button.click()\n", |
|
|
68 |
"\n", |
|
|
69 |
"\n", |
|
|
70 |
"except TimeoutException:\n", |
|
|
71 |
" print(\"The radio button was not found or is not interactable.\")\n", |
|
|
72 |
" print(driver.page_source)\n", |
|
|
73 |
"\n", |
|
|
74 |
"\n" |
|
|
75 |
] |
|
|
76 |
}, |
|
|
77 |
{ |
|
|
78 |
"cell_type": "code", |
|
|
79 |
"execution_count": 14, |
|
|
80 |
"metadata": {}, |
|
|
81 |
"outputs": [ |
|
|
82 |
{ |
|
|
83 |
"name": "stdout", |
|
|
84 |
"output_type": "stream", |
|
|
85 |
"text": [ |
|
|
86 |
"Recruiting option selected successfully.\n", |
|
|
87 |
"Search button clicked, navigating to the results page.\n" |
|
|
88 |
] |
|
|
89 |
} |
|
|
90 |
], |
|
|
91 |
"source": [ |
|
|
92 |
"from selenium import webdriver\n", |
|
|
93 |
"from selenium.webdriver.common.by import By\n", |
|
|
94 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
95 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
96 |
"from selenium.common.exceptions import TimeoutException\n", |
|
|
97 |
"import time\n", |
|
|
98 |
"\n", |
|
|
99 |
"# Set up the driver and open the page\n", |
|
|
100 |
"driver = webdriver.Chrome()\n", |
|
|
101 |
"driver.set_window_size(1120, 1000)\n", |
|
|
102 |
"driver.get(\"https://clinicaltrials.gov\")\n", |
|
|
103 |
"\n", |
|
|
104 |
"try:\n", |
|
|
105 |
" # Wait for the radio group container to be visible\n", |
|
|
106 |
" WebDriverWait(driver, 20).until(\n", |
|
|
107 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[2]/ctg-search-filters-form/div[2]'))\n", |
|
|
108 |
" )\n", |
|
|
109 |
"\n", |
|
|
110 |
" # Scroll down slowly to the radio button section\n", |
|
|
111 |
" driver.execute_script(\"window.scrollBy(0, 600);\") # Adjust scrolling value as needed\n", |
|
|
112 |
" time.sleep(1) # Give time for the scrolling action to be visually clear\n", |
|
|
113 |
"\n", |
|
|
114 |
" # Locate and click the 'Recruiting and not yet recruiting studies' radio button\n", |
|
|
115 |
" recruiting_radio_button = WebDriverWait(driver, 20).until(\n", |
|
|
116 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div/div[2]')) #//*[@id=\"adv-check-status\"]/div/div[2]\n", |
|
|
117 |
" # //*[@id=\"adv-check-status\"]/div/div[2]\n", |
|
|
118 |
" )\n", |
|
|
119 |
"\n", |
|
|
120 |
" # Scroll the page to bring the radio button into view and click it\n", |
|
|
121 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", recruiting_radio_button)\n", |
|
|
122 |
" time.sleep(1) # Pause before interacting\n", |
|
|
123 |
"\n", |
|
|
124 |
" # Ensure the 'Recruiting and not yet recruiting' radio button is selected\n", |
|
|
125 |
" recruiting_radio_button.click()\n", |
|
|
126 |
" time.sleep(1) # Wait a bit to confirm the selection\n", |
|
|
127 |
" \n", |
|
|
128 |
" # Optionally verify the selection\n", |
|
|
129 |
" selected_status = driver.find_element(By.XPATH, '//*[@id=\"adv-radio-status1\"]').is_selected()\n", |
|
|
130 |
" if selected_status:\n", |
|
|
131 |
" print(\"Recruiting option selected successfully.\")\n", |
|
|
132 |
" else:\n", |
|
|
133 |
" print(\"Failed to select Recruiting option.\")\n", |
|
|
134 |
"\n", |
|
|
135 |
" # Now, wait for the search button to be visible\n", |
|
|
136 |
" search_button = WebDriverWait(driver, 20).until(\n", |
|
|
137 |
" EC.element_to_be_clickable((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[3]/div/div/button'))\n", |
|
|
138 |
" )\n", |
|
|
139 |
"\n", |
|
|
140 |
" # Scroll the page to bring the search button into view (just in case)\n", |
|
|
141 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", search_button)\n", |
|
|
142 |
" time.sleep(1) # Wait a bit before clicking\n", |
|
|
143 |
"\n", |
|
|
144 |
" # Click the search button\n", |
|
|
145 |
" search_button.click()\n", |
|
|
146 |
" print(\"Search button clicked, navigating to the results page.\")\n", |
|
|
147 |
"\n", |
|
|
148 |
"except TimeoutException:\n", |
|
|
149 |
" print(\"The search button was not found or is not interactable.\")\n", |
|
|
150 |
" print(driver.page_source)\n" |
|
|
151 |
] |
|
|
152 |
}, |
|
|
153 |
{ |
|
|
154 |
"cell_type": "code", |
|
|
155 |
"execution_count": 16, |
|
|
156 |
"metadata": {}, |
|
|
157 |
"outputs": [ |
|
|
158 |
{ |
|
|
159 |
"name": "stdout", |
|
|
160 |
"output_type": "stream", |
|
|
161 |
"text": [ |
|
|
162 |
"Recruiting option selected successfully.\n", |
|
|
163 |
"Search button clicked, navigating to the results page.\n", |
|
|
164 |
"'Not yet recruiting' checkbox was already unselected.\n", |
|
|
165 |
"An error occurred: Message: \n", |
|
|
166 |
"\n" |
|
|
167 |
] |
|
|
168 |
} |
|
|
169 |
], |
|
|
170 |
"source": [ |
|
|
171 |
"from selenium import webdriver\n", |
|
|
172 |
"from selenium.webdriver.common.by import By\n", |
|
|
173 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
174 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
175 |
"import time\n", |
|
|
176 |
"\n", |
|
|
177 |
"# Set up the driver and open the main Clinical Trials page\n", |
|
|
178 |
"driver = webdriver.Chrome()\n", |
|
|
179 |
"driver.set_window_size(1120, 1000)\n", |
|
|
180 |
"driver.get(\"https://clinicaltrials.gov\")\n", |
|
|
181 |
"\n", |
|
|
182 |
"try:\n", |
|
|
183 |
" # ----- FIRST PAGE -----\n", |
|
|
184 |
" # Wait for the radio group container to be visible\n", |
|
|
185 |
" WebDriverWait(driver, 20).until(\n", |
|
|
186 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[2]/ctg-search-filters-form/div[2]'))\n", |
|
|
187 |
" )\n", |
|
|
188 |
"\n", |
|
|
189 |
" # Scroll down slowly to the radio button section\n", |
|
|
190 |
" driver.execute_script(\"window.scrollBy(0, 600);\") # Adjust scrolling value as needed\n", |
|
|
191 |
" time.sleep(1) # Give time for the scrolling action to be visually clear\n", |
|
|
192 |
"\n", |
|
|
193 |
"\n", |
|
|
194 |
" # Locate and click the 'Recruiting and not yet recruiting studies' radio button\n", |
|
|
195 |
" recruiting_radio_button = WebDriverWait(driver, 20).until(\n", |
|
|
196 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div/div[2]'))\n", |
|
|
197 |
" )\n", |
|
|
198 |
" \n", |
|
|
199 |
" # Scroll the page to bring the radio button into view and click it\n", |
|
|
200 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", recruiting_radio_button)\n", |
|
|
201 |
" time.sleep(1) # Pause before interacting\n", |
|
|
202 |
" \n", |
|
|
203 |
" # Ensure the 'Recruiting and not yet recruiting' radio button is selected\n", |
|
|
204 |
" recruiting_radio_button.click()\n", |
|
|
205 |
" time.sleep(1) # Wait a bit to confirm the selection\n", |
|
|
206 |
" \n", |
|
|
207 |
" # Optionally verify the selection\n", |
|
|
208 |
" selected_status = driver.find_element(By.XPATH, '//*[@id=\"adv-radio-status1\"]').is_selected()\n", |
|
|
209 |
" if selected_status:\n", |
|
|
210 |
" print(\"Recruiting option selected successfully.\")\n", |
|
|
211 |
" else:\n", |
|
|
212 |
" print(\"Failed to select Recruiting option.\")\n", |
|
|
213 |
" \n", |
|
|
214 |
" \n", |
|
|
215 |
" # Now, wait for the search button to be visible\n", |
|
|
216 |
" search_button = WebDriverWait(driver, 20).until(\n", |
|
|
217 |
" EC.element_to_be_clickable((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[3]/div/div/button'))\n", |
|
|
218 |
" )\n", |
|
|
219 |
" \n", |
|
|
220 |
" # Scroll the page to bring the search button into view (just in case)\n", |
|
|
221 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", search_button)\n", |
|
|
222 |
" time.sleep(1) # Wait a bit before clicking\n", |
|
|
223 |
" \n", |
|
|
224 |
" # Click the search button\n", |
|
|
225 |
" search_button.click()\n", |
|
|
226 |
" print(\"Search button clicked, navigating to the results page.\")\n", |
|
|
227 |
"\n", |
|
|
228 |
" \n", |
|
|
229 |
" # Wait for the second page to load\n", |
|
|
230 |
" time.sleep(5) # You may want to adjust this based on your internet speed\n", |
|
|
231 |
"\n", |
|
|
232 |
" # ----- SECOND PAGE -----\n", |
|
|
233 |
" # Wait for the filter container to be visible on the second page\n", |
|
|
234 |
" filter_container = WebDriverWait(driver, 20).until(\n", |
|
|
235 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-search-results-page/div[2]/section/div[1]/ctg-focus-your-search-panel/div/div[2]/ctg-search-filters-form'))\n", |
|
|
236 |
" )\n", |
|
|
237 |
"\n", |
|
|
238 |
" # Scroll to the filter container\n", |
|
|
239 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", filter_container)\n", |
|
|
240 |
" time.sleep(1)\n", |
|
|
241 |
"\n", |
|
|
242 |
" # Locate the \"Not yet recruiting\" checkbox and unselect it if it's selected\n", |
|
|
243 |
" not_yet_recruiting_checkbox = WebDriverWait(driver, 20).until(\n", |
|
|
244 |
" EC.element_to_be_clickable((By.XPATH, '//*[@id=\"adv-check-status\"]/div[2]/div[1]'))\n", |
|
|
245 |
" )\n", |
|
|
246 |
" \n", |
|
|
247 |
" # Unselect the checkbox if it's selected\n", |
|
|
248 |
" if not_yet_recruiting_checkbox.is_selected():\n", |
|
|
249 |
" not_yet_recruiting_checkbox.click()\n", |
|
|
250 |
" print(\"Unselected the 'Not yet recruiting' checkbox.\")\n", |
|
|
251 |
" else:\n", |
|
|
252 |
" print(\"'Not yet recruiting' checkbox was already unselected.\")\n", |
|
|
253 |
"\n", |
|
|
254 |
" # Scroll to the Apply Filters button\n", |
|
|
255 |
" apply_filters_button = WebDriverWait(driver, 20).until(\n", |
|
|
256 |
" EC.element_to_be_clickable((By.XPATH, '//*[@id=\"apply-filters\"]'))\n", |
|
|
257 |
" )\n", |
|
|
258 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", apply_filters_button)\n", |
|
|
259 |
" time.sleep(1)\n", |
|
|
260 |
"\n", |
|
|
261 |
" # Click the Apply Filters button\n", |
|
|
262 |
" apply_filters_button.click()\n", |
|
|
263 |
" print(\"Clicked the 'Apply filters' button.\")\n", |
|
|
264 |
"\n", |
|
|
265 |
"except Exception as e:\n", |
|
|
266 |
" print(\"An error occurred:\", e)\n", |
|
|
267 |
"\n" |
|
|
268 |
] |
|
|
269 |
}, |
|
|
270 |
{ |
|
|
271 |
"cell_type": "code", |
|
|
272 |
"execution_count": 20, |
|
|
273 |
"metadata": {}, |
|
|
274 |
"outputs": [ |
|
|
275 |
{ |
|
|
276 |
"name": "stdout", |
|
|
277 |
"output_type": "stream", |
|
|
278 |
"text": [ |
|
|
279 |
"Waiting for the filter container to load...\n", |
|
|
280 |
"Filter container loaded successfully.\n", |
|
|
281 |
"Verifying the 'Not yet recruiting' checkbox...\n", |
|
|
282 |
"Checkbox 'Not yet recruiting' found.\n", |
|
|
283 |
"Checkbox is already unselected.\n", |
|
|
284 |
"Verifying the 'Apply Filters' button...\n", |
|
|
285 |
"An error occurred: Message: \n", |
|
|
286 |
"\n", |
|
|
287 |
"Script completed. Keeping the browser window open.\n" |
|
|
288 |
] |
|
|
289 |
} |
|
|
290 |
], |
|
|
291 |
"source": [ |
|
|
292 |
"from selenium import webdriver\n", |
|
|
293 |
"from selenium.webdriver.common.by import By\n", |
|
|
294 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
295 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
296 |
"import time\n", |
|
|
297 |
"\n", |
|
|
298 |
"# Set up the driver and open the specific page directly\n", |
|
|
299 |
"driver = webdriver.Chrome()\n", |
|
|
300 |
"driver.set_window_size(1120, 1000)\n", |
|
|
301 |
"driver.get(\"https://clinicaltrials.gov/search?aggFilters=status:not%20rec\")\n", |
|
|
302 |
"\n", |
|
|
303 |
"try:\n", |
|
|
304 |
" # ----- STEP 1: Verify filter container -----\n", |
|
|
305 |
" print(\"Waiting for the filter container to load...\")\n", |
|
|
306 |
" filter_container = WebDriverWait(driver, 20).until(\n", |
|
|
307 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-search-results-page/div[2]/section/div[1]/ctg-focus-your-search-panel/div/div[2]/ctg-search-filters-form'))\n", |
|
|
308 |
" )\n", |
|
|
309 |
" print(\"Filter container loaded successfully.\")\n", |
|
|
310 |
" time.sleep(2) # Pause for visual confirmation\n", |
|
|
311 |
"\n", |
|
|
312 |
" # ----- STEP 2: Verify 'Not yet recruiting' checkbox -----\n", |
|
|
313 |
" print(\"Verifying the 'Not yet recruiting' checkbox...\")\n", |
|
|
314 |
" not_yet_recruiting_checkbox = WebDriverWait(driver, 20).until(\n", |
|
|
315 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div[2]/div[1]'))\n", |
|
|
316 |
" )\n", |
|
|
317 |
" print(\"Checkbox 'Not yet recruiting' found.\")\n", |
|
|
318 |
" time.sleep(2) # Pause for visual confirmation\n", |
|
|
319 |
"\n", |
|
|
320 |
" # Check if it's selected, and unselect if it is\n", |
|
|
321 |
" if not_yet_recruiting_checkbox.is_selected():\n", |
|
|
322 |
" print(\"Checkbox is selected, unselecting it...\")\n", |
|
|
323 |
" not_yet_recruiting_checkbox.click()\n", |
|
|
324 |
" print(\"Checkbox unselected successfully.\")\n", |
|
|
325 |
" else:\n", |
|
|
326 |
" print(\"Checkbox is already unselected.\")\n", |
|
|
327 |
" time.sleep(2) # Pause for visual confirmation\n", |
|
|
328 |
"\n", |
|
|
329 |
" # ----- STEP 3: Verify 'Apply Filters' button -----\n", |
|
|
330 |
" print(\"Verifying the 'Apply Filters' button...\")\n", |
|
|
331 |
" apply_filters_button = WebDriverWait(driver, 20).until(\n", |
|
|
332 |
" EC.element_to_be_clickable((By.XPATH, '//*[@id=\"apply-filters\"]'))\n", |
|
|
333 |
" )\n", |
|
|
334 |
" print(\"'Apply Filters' button is available.\")\n", |
|
|
335 |
" time.sleep(2) # Pause for visual confirmation\n", |
|
|
336 |
"\n", |
|
|
337 |
" # ----- STEP 4: Click 'Apply Filters' -----\n", |
|
|
338 |
" print(\"Clicking the 'Apply Filters' button...\")\n", |
|
|
339 |
" apply_filters_button.click()\n", |
|
|
340 |
" print(\"Clicked 'Apply Filters'.\")\n", |
|
|
341 |
" time.sleep(2) # Pause for visual confirmation of the results after applying the filter\n", |
|
|
342 |
"\n", |
|
|
343 |
"except Exception as e:\n", |
|
|
344 |
" print(\"An error occurred:\", e)\n", |
|
|
345 |
"\n", |
|
|
346 |
"finally:\n", |
|
|
347 |
" # Keep the browser open\n", |
|
|
348 |
" print(\"Script completed. Keeping the browser window open.\")\n", |
|
|
349 |
" input(\"Press Enter to close the browser window...\")\n", |
|
|
350 |
" driver.quit() # Only quits when you press Enter\n" |
|
|
351 |
] |
|
|
352 |
}, |
|
|
353 |
{ |
|
|
354 |
"cell_type": "code", |
|
|
355 |
"execution_count": 22, |
|
|
356 |
"metadata": {}, |
|
|
357 |
"outputs": [ |
|
|
358 |
{ |
|
|
359 |
"name": "stdout", |
|
|
360 |
"output_type": "stream", |
|
|
361 |
"text": [ |
|
|
362 |
"Filter container loaded successfully.\n", |
|
|
363 |
"Scrolling the filter container...\n", |
|
|
364 |
"Script completed. Keeping the browser window open.\n" |
|
|
365 |
] |
|
|
366 |
} |
|
|
367 |
], |
|
|
368 |
"source": [ |
|
|
369 |
"# ----- FIRST PAGE -----\n", |
|
|
370 |
"# Wait for the filter group container to be visible\n", |
|
|
371 |
"from selenium import webdriver\n", |
|
|
372 |
"from selenium.webdriver.common.by import By\n", |
|
|
373 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
374 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
375 |
"import time\n", |
|
|
376 |
"\n", |
|
|
377 |
"# Set up the driver\n", |
|
|
378 |
"driver = webdriver.Chrome()\n", |
|
|
379 |
"driver.set_window_size(1120, 1000)\n", |
|
|
380 |
"\n", |
|
|
381 |
"# Navigate to the page\n", |
|
|
382 |
"driver.get(\"https://clinicaltrials.gov/search?aggFilters=status:not%20rec\")\n", |
|
|
383 |
"\n", |
|
|
384 |
"try:\n", |
|
|
385 |
" # Step 1: Wait for the filter container to load\n", |
|
|
386 |
" filter_container = WebDriverWait(driver, 20).until(\n", |
|
|
387 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-search-results-page/div[2]/section/div[1]/ctg-focus-your-search-panel/div/div[2]/ctg-search-filters-form'))\n", |
|
|
388 |
" )\n", |
|
|
389 |
" print(\"Filter container loaded successfully.\")\n", |
|
|
390 |
" time.sleep(2)\n", |
|
|
391 |
"\n", |
|
|
392 |
" # Step 2: Scroll within the filter container using JavaScript\n", |
|
|
393 |
" print(\"Scrolling the filter container...\")\n", |
|
|
394 |
" \n", |
|
|
395 |
" # Scroll by a specific amount (e.g., 500 pixels)\n", |
|
|
396 |
" driver.execute_script(\"arguments[0].scrollTop = arguments[0].scrollTop + 500;\", filter_container)\n", |
|
|
397 |
" \n", |
|
|
398 |
" # Alternatively, you can scroll to the bottom of the container:\n", |
|
|
399 |
" # driver.execute_script(\"arguments[0].scrollTop = arguments[0].scrollHeight;\", filter_container)\n", |
|
|
400 |
" \n", |
|
|
401 |
" time.sleep(2) # Pause for visual confirmation\n", |
|
|
402 |
"\n", |
|
|
403 |
"except Exception as e:\n", |
|
|
404 |
" print(\"An error occurred:\", e)\n", |
|
|
405 |
"\n", |
|
|
406 |
"finally:\n", |
|
|
407 |
" # Keep the browser open\n", |
|
|
408 |
" print(\"Script completed. Keeping the browser window open.\")\n", |
|
|
409 |
" input(\"Press Enter to close the browser window...\")\n", |
|
|
410 |
" driver.quit()\n", |
|
|
411 |
" # Pause for visual confirmation\n", |
|
|
412 |
"\n", |
|
|
413 |
"\n", |
|
|
414 |
"# # Locate and click the 'Recruiting and not yet recruiting studies' radio button\n", |
|
|
415 |
"# recruiting_radio_button = WebDriverWait(driver, 20).until(\n", |
|
|
416 |
"# EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div/div[2]'))\n", |
|
|
417 |
"# )\n", |
|
|
418 |
"\n", |
|
|
419 |
"# # Scroll the page to bring the radio button into view and click it\n", |
|
|
420 |
"# driver.execute_script(\"arguments[0].scrollIntoView(true);\", recruiting_radio_button)\n", |
|
|
421 |
"# time.sleep(1) # Pause before interacting\n", |
|
|
422 |
"\n", |
|
|
423 |
"# # Ensure the 'Recruiting and not yet recruiting' radio button is selected\n", |
|
|
424 |
"# recruiting_radio_button.click()\n", |
|
|
425 |
"# time.sleep(1) # Wait a bit to confirm the selection\n", |
|
|
426 |
"\n", |
|
|
427 |
"# # Optionally verify the selection\n", |
|
|
428 |
"# selected_status = driver.find_element(By.XPATH, '//*[@id=\"adv-radio-status1\"]').is_selected()\n", |
|
|
429 |
"# if selected_status:\n", |
|
|
430 |
"# print(\"Recruiting option selected successfully.\")\n", |
|
|
431 |
"# else:\n", |
|
|
432 |
"# print(\"Failed to select Recruiting option.\")\n", |
|
|
433 |
" \n", |
|
|
434 |
"\n", |
|
|
435 |
"# # Now, wait for the search button to be visible\n", |
|
|
436 |
"# search_button = WebDriverWait(driver, 20).until(\n", |
|
|
437 |
"# EC.element_to_be_clickable((By.XPATH, '//*[@id=\"main-content\"]/ctg-home/div/div[2]/ctg-home-search-panel/div/div[3]/div/div/button'))\n", |
|
|
438 |
"# )\n", |
|
|
439 |
"\n", |
|
|
440 |
"# # Scroll the page to bring the search button into view (just in case)\n", |
|
|
441 |
"# driver.execute_script(\"arguments[0].scrollIntoView(true);\", search_button)\n", |
|
|
442 |
"# time.sleep(1) # Wait a bit before clicking\n", |
|
|
443 |
"\n", |
|
|
444 |
"# # Click the search button\n", |
|
|
445 |
"# search_button.click()\n", |
|
|
446 |
"# print(\"Search button clicked, navigating to the results page.\")\n", |
|
|
447 |
"\n", |
|
|
448 |
"\n", |
|
|
449 |
"# # Wait for the second page to load\n", |
|
|
450 |
"# time.sleep(5) # You may want to adjust this based on your internet speed\n", |
|
|
451 |
"\n" |
|
|
452 |
] |
|
|
453 |
}, |
|
|
454 |
{ |
|
|
455 |
"cell_type": "code", |
|
|
456 |
"execution_count": 26, |
|
|
457 |
"metadata": {}, |
|
|
458 |
"outputs": [ |
|
|
459 |
{ |
|
|
460 |
"name": "stdout", |
|
|
461 |
"output_type": "stream", |
|
|
462 |
"text": [ |
|
|
463 |
"Filter container loaded successfully.\n", |
|
|
464 |
"Script completed. Keeping the browser window open.\n" |
|
|
465 |
] |
|
|
466 |
} |
|
|
467 |
], |
|
|
468 |
"source": [ |
|
|
469 |
"from selenium import webdriver\n", |
|
|
470 |
"from selenium.webdriver.common.by import By\n", |
|
|
471 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
472 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
473 |
"import time\n", |
|
|
474 |
"\n", |
|
|
475 |
"# Set up the driver\n", |
|
|
476 |
"driver = webdriver.Chrome()\n", |
|
|
477 |
"driver.set_window_size(1120, 1000)\n", |
|
|
478 |
"\n", |
|
|
479 |
"# Navigate to the page\n", |
|
|
480 |
"driver.get(\"https://clinicaltrials.gov/search?aggFilters=status:not%20rec\")\n", |
|
|
481 |
"\n", |
|
|
482 |
"try:\n", |
|
|
483 |
" # Wait for the filter container to be visible\n", |
|
|
484 |
" filter_container = WebDriverWait(driver, 20).until(\n", |
|
|
485 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"main-content\"]/ctg-search-results-page/div[2]/section/div[1]/ctg-focus-your-search-panel/div/div[2]/ctg-search-filters-form'))\n", |
|
|
486 |
" )\n", |
|
|
487 |
" \n", |
|
|
488 |
" print(\"Filter container loaded successfully.\")\n", |
|
|
489 |
" \n", |
|
|
490 |
" # Highlight the filter container by adding a red border around it\n", |
|
|
491 |
" driver.execute_script(\"arguments[0].style.border='3px solid red'\", filter_container)\n", |
|
|
492 |
" \n", |
|
|
493 |
" # Pause to visually inspect the browser\n", |
|
|
494 |
" time.sleep(5) # Adjust this if needed for more time to inspect\n", |
|
|
495 |
"\n", |
|
|
496 |
"except Exception as e:\n", |
|
|
497 |
" print(\"An error occurred:\", e)\n", |
|
|
498 |
"\n", |
|
|
499 |
"finally:\n", |
|
|
500 |
" # Keep the browser open for visual confirmation\n", |
|
|
501 |
" print(\"Script completed. Keeping the browser window open.\")\n", |
|
|
502 |
" input(\"Press Enter to close the browser window...\")\n", |
|
|
503 |
" driver.quit()\n" |
|
|
504 |
] |
|
|
505 |
}, |
|
|
506 |
{ |
|
|
507 |
"cell_type": "code", |
|
|
508 |
"execution_count": 27, |
|
|
509 |
"metadata": {}, |
|
|
510 |
"outputs": [ |
|
|
511 |
{ |
|
|
512 |
"name": "stdout", |
|
|
513 |
"output_type": "stream", |
|
|
514 |
"text": [ |
|
|
515 |
"Not Yet Recruiting button loaded successfully.\n", |
|
|
516 |
"Script completed. Keeping the browser window open.\n" |
|
|
517 |
] |
|
|
518 |
} |
|
|
519 |
], |
|
|
520 |
"source": [ |
|
|
521 |
"from selenium import webdriver\n", |
|
|
522 |
"from selenium.webdriver.common.by import By\n", |
|
|
523 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
524 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
525 |
"import time\n", |
|
|
526 |
"\n", |
|
|
527 |
"# Set up the driver\n", |
|
|
528 |
"driver = webdriver.Chrome()\n", |
|
|
529 |
"driver.set_window_size(1120, 1000)\n", |
|
|
530 |
"\n", |
|
|
531 |
"# Navigate to the page\n", |
|
|
532 |
"driver.get(\"https://clinicaltrials.gov/search?aggFilters=status:not%20rec\")\n", |
|
|
533 |
"\n", |
|
|
534 |
"try:\n", |
|
|
535 |
" # Wait for the \"Not Yet Recruiting\" radio button to be visible\n", |
|
|
536 |
" not_yet_recruiting_button = WebDriverWait(driver, 20).until(\n", |
|
|
537 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div[2]/div[1]'))\n", |
|
|
538 |
" )\n", |
|
|
539 |
" \n", |
|
|
540 |
" print(\"Not Yet Recruiting button loaded successfully.\")\n", |
|
|
541 |
" \n", |
|
|
542 |
" # Highlight the \"Not Yet Recruiting\" button by adding a red border around it\n", |
|
|
543 |
" driver.execute_script(\"arguments[0].style.border='3px solid red'\", not_yet_recruiting_button)\n", |
|
|
544 |
" \n", |
|
|
545 |
" # Pause to visually inspect the browser\n", |
|
|
546 |
" time.sleep(5) # Adjust this if needed for more time to inspect\n", |
|
|
547 |
"\n", |
|
|
548 |
"except Exception as e:\n", |
|
|
549 |
" print(\"An error occurred:\", e)\n", |
|
|
550 |
"\n", |
|
|
551 |
"finally:\n", |
|
|
552 |
" # Keep the browser open for visual confirmation\n", |
|
|
553 |
" print(\"Script completed. Keeping the browser window open.\")\n", |
|
|
554 |
" input(\"Press Enter to close the browser window...\")\n", |
|
|
555 |
" driver.quit()\n" |
|
|
556 |
] |
|
|
557 |
}, |
|
|
558 |
{ |
|
|
559 |
"cell_type": "code", |
|
|
560 |
"execution_count": 35, |
|
|
561 |
"metadata": {}, |
|
|
562 |
"outputs": [ |
|
|
563 |
{ |
|
|
564 |
"name": "stdout", |
|
|
565 |
"output_type": "stream", |
|
|
566 |
"text": [ |
|
|
567 |
"Not Yet Recruiting checkbox loaded successfully.\n", |
|
|
568 |
"Not Yet Recruiting checkbox is currently selected. Unselecting it...\n", |
|
|
569 |
"Not Yet Recruiting checkbox has been unselected.\n", |
|
|
570 |
"Script completed. Keeping the browser window open.\n" |
|
|
571 |
] |
|
|
572 |
}, |
|
|
573 |
{ |
|
|
574 |
"ename": "KeyboardInterrupt", |
|
|
575 |
"evalue": "Interrupted by user", |
|
|
576 |
"output_type": "error", |
|
|
577 |
"traceback": [ |
|
|
578 |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
|
579 |
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", |
|
|
580 |
"Cell \u001b[0;32mIn[35], line 50\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[1;32m 48\u001b[0m \u001b[38;5;66;03m# Keep the browser open for visual confirmation\u001b[39;00m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mScript completed. Keeping the browser window open.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 50\u001b[0m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mPress Enter to close the browser window...\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 51\u001b[0m driver\u001b[38;5;241m.\u001b[39mquit()\n", |
|
|
581 |
"File \u001b[0;32m~/Desktop/patient-trials-matching/env/lib/python3.9/site-packages/ipykernel/kernelbase.py:1282\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m 1280\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1281\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(msg)\n\u001b[0;32m-> 1282\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1283\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1286\u001b[0m \u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1287\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", |
|
|
582 |
"File \u001b[0;32m~/Desktop/patient-trials-matching/env/lib/python3.9/site-packages/ipykernel/kernelbase.py:1325\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m 1322\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[1;32m 1323\u001b[0m \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m 1324\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m-> 1325\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(msg) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1326\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[1;32m 1327\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n", |
|
|
583 |
"\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user" |
|
|
584 |
] |
|
|
585 |
} |
|
|
586 |
], |
|
|
587 |
"source": [ |
|
|
588 |
"from selenium import webdriver\n", |
|
|
589 |
"from selenium.webdriver.common.by import By\n", |
|
|
590 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
591 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
592 |
"import time\n", |
|
|
593 |
"\n", |
|
|
594 |
"# Set up the driver\n", |
|
|
595 |
"driver = webdriver.Chrome()\n", |
|
|
596 |
"driver.set_window_size(1120, 1000)\n", |
|
|
597 |
"\n", |
|
|
598 |
"# Navigate to the page\n", |
|
|
599 |
"driver.get(\"https://clinicaltrials.gov/search?aggFilters=status:not%20rec\")\n", |
|
|
600 |
"\n", |
|
|
601 |
"try:\n", |
|
|
602 |
" # Wait for the \"Not Yet Recruiting\" checkbox to be visible\n", |
|
|
603 |
" not_yet_recruiting_checkbox = WebDriverWait(driver, 20).until(\n", |
|
|
604 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"adv-check-status\"]/div[2]/div[1]'))\n", |
|
|
605 |
" )\n", |
|
|
606 |
" \n", |
|
|
607 |
" print(\"Not Yet Recruiting checkbox loaded successfully.\")\n", |
|
|
608 |
" \n", |
|
|
609 |
" # Check if the checkbox is selected\n", |
|
|
610 |
" checkbox_input = not_yet_recruiting_checkbox.find_element(By.TAG_NAME, 'input')\n", |
|
|
611 |
" \n", |
|
|
612 |
" if checkbox_input.is_selected():\n", |
|
|
613 |
" print(\"Not Yet Recruiting checkbox is currently selected. Unselecting it...\")\n", |
|
|
614 |
" \n", |
|
|
615 |
" # Scroll into view\n", |
|
|
616 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", not_yet_recruiting_checkbox)\n", |
|
|
617 |
" \n", |
|
|
618 |
" # Use JavaScript to click the checkbox to unselect it\n", |
|
|
619 |
" driver.execute_script(\"arguments[0].click();\", checkbox_input)\n", |
|
|
620 |
"\n", |
|
|
621 |
" # Highlight it after unselecting\n", |
|
|
622 |
" driver.execute_script(\"arguments[0].style.border='3px solid red'\", not_yet_recruiting_checkbox)\n", |
|
|
623 |
"\n", |
|
|
624 |
" print(\"Not Yet Recruiting checkbox has been unselected.\")\n", |
|
|
625 |
" else:\n", |
|
|
626 |
" print(\"Not Yet Recruiting checkbox is already unselected.\")\n", |
|
|
627 |
"\n", |
|
|
628 |
" # Pause to visually inspect the browser\n", |
|
|
629 |
" time.sleep(5) # Adjust this if needed for more time to inspect\n", |
|
|
630 |
"\n", |
|
|
631 |
"except Exception as e:\n", |
|
|
632 |
" print(\"An error occurred:\", e)\n", |
|
|
633 |
"\n", |
|
|
634 |
"finally:\n", |
|
|
635 |
" # Keep the browser open for visual confirmation\n", |
|
|
636 |
" print(\"Script completed. Keeping the browser window open.\")\n", |
|
|
637 |
" input(\"Press Enter to close the browser window...\")\n", |
|
|
638 |
" driver.quit()\n" |
|
|
639 |
] |
|
|
640 |
}, |
|
|
641 |
{ |
|
|
642 |
"cell_type": "code", |
|
|
643 |
"execution_count": 1, |
|
|
644 |
"metadata": {}, |
|
|
645 |
"outputs": [ |
|
|
646 |
{ |
|
|
647 |
"name": "stdout", |
|
|
648 |
"output_type": "stream", |
|
|
649 |
"text": [ |
|
|
650 |
"Eligibility Criteria container loaded successfully.\n", |
|
|
651 |
"Eligibility Criteria:\n", |
|
|
652 |
"Description\n", |
|
|
653 |
"Inclusion Criteria:\n", |
|
|
654 |
"Age ≥ 18 years at inclusion date\n", |
|
|
655 |
"Schirmer's test ≤ 5 mm for both eyes\n", |
|
|
656 |
"NIBUT ≤ 10 s for both eyes\n", |
|
|
657 |
"Previous positive result of blood test for sample anti-Ro (SS-A) or anti-La (SS-B), as indicated by medical record or lab result shown by the subject.\n", |
|
|
658 |
"The study subject reports having understood and have signed the Informed Consent Form (ICF) and is willing to comply with all investigation visits and assessments.\n", |
|
|
659 |
"Women of childbearing potential must agree to use a reliable, medically approved form of contraception during the study participation until end of study.\n", |
|
|
660 |
"Anticipated compliance with prescribed treatment and follow-up.\n", |
|
|
661 |
"Exclusion Criteria:\n", |
|
|
662 |
"Recently (12 months prior enrolment) undergone nasal, sinus, or ocular surgery.\n", |
|
|
663 |
"Presence of an ocular or respiratory condition that could affect the study parameters such as active ocular infection/inflammation, glaucoma, diabetic retinopathy, or upper respiratory tract infection per the Investigator's judgement.\n", |
|
|
664 |
"The study subject has a cognitive incapacity or language barrier precluding adequate understanding or cooperation.\n", |
|
|
665 |
"Any severe diseases interfering with the performance, evaluation, and outcome of the clinical evaluation.\n", |
|
|
666 |
"The study subject is considered by the Investigator to be unsuitable to participate in the investigation for any other reason.\n", |
|
|
667 |
"Previous (within 30 days prior to enrolment) and concurrent treatment with another investigational drug/s or device/s.\n", |
|
|
668 |
"Subject is pregnant or lactating or planning to get pregnant during the duration of the study.\n", |
|
|
669 |
"Show less\n", |
|
|
670 |
"Ages Eligible for Study\n", |
|
|
671 |
"18 Years and older (Adult, Older Adult )\n", |
|
|
672 |
"Sexes Eligible for Study\n", |
|
|
673 |
"All\n", |
|
|
674 |
"Accepts Healthy Volunteers\n", |
|
|
675 |
"No\n" |
|
|
676 |
] |
|
|
677 |
} |
|
|
678 |
], |
|
|
679 |
"source": [ |
|
|
680 |
"from selenium import webdriver\n", |
|
|
681 |
"from selenium.webdriver.common.by import By\n", |
|
|
682 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
683 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
684 |
"import time\n", |
|
|
685 |
"\n", |
|
|
686 |
"# Set up the Selenium WebDriver\n", |
|
|
687 |
"driver = webdriver.Chrome()\n", |
|
|
688 |
"\n", |
|
|
689 |
"# Navigate to the webpage\n", |
|
|
690 |
"driver.get('https://clinicaltrials.gov/study/NCT06626477#participation-criteria')\n", |
|
|
691 |
"\n", |
|
|
692 |
"# Wait for the \"Eligibility Criteria\" container to load\n", |
|
|
693 |
"try:\n", |
|
|
694 |
" eligibility_criteria_container = WebDriverWait(driver, 20).until(\n", |
|
|
695 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]'))\n", |
|
|
696 |
" )\n", |
|
|
697 |
" \n", |
|
|
698 |
" print(\"Eligibility Criteria container loaded successfully.\")\n", |
|
|
699 |
" \n", |
|
|
700 |
" # Extract the text from the eligibility container\n", |
|
|
701 |
" eligibility_text = eligibility_criteria_container.text\n", |
|
|
702 |
" print(\"Eligibility Criteria:\")\n", |
|
|
703 |
" print(eligibility_text)\n", |
|
|
704 |
" \n", |
|
|
705 |
" # Optionally save the data to a text file\n", |
|
|
706 |
" with open('eligibility_criteria.txt', 'w') as file:\n", |
|
|
707 |
" file.write(eligibility_text)\n", |
|
|
708 |
" \n", |
|
|
709 |
"except Exception as e:\n", |
|
|
710 |
" print(\"An error occurred:\", e)\n", |
|
|
711 |
"\n", |
|
|
712 |
"finally:\n", |
|
|
713 |
" # Pause to visually inspect the browser\n", |
|
|
714 |
" time.sleep(5)\n", |
|
|
715 |
"\n", |
|
|
716 |
" # Close the browser\n", |
|
|
717 |
" driver.quit()\n" |
|
|
718 |
] |
|
|
719 |
}, |
|
|
720 |
{ |
|
|
721 |
"cell_type": "code", |
|
|
722 |
"execution_count": 3, |
|
|
723 |
"metadata": {}, |
|
|
724 |
"outputs": [ |
|
|
725 |
{ |
|
|
726 |
"name": "stdout", |
|
|
727 |
"output_type": "stream", |
|
|
728 |
"text": [ |
|
|
729 |
"Eligibility Criteria container loaded successfully.\n", |
|
|
730 |
"[]\n", |
|
|
731 |
"[]\n", |
|
|
732 |
"\n", |
|
|
733 |
"Data successfully written to eligibility_criteria_dynamic.txt\n" |
|
|
734 |
] |
|
|
735 |
} |
|
|
736 |
], |
|
|
737 |
"source": [ |
|
|
738 |
"from selenium import webdriver\n", |
|
|
739 |
"from selenium.webdriver.common.by import By\n", |
|
|
740 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
741 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
742 |
"import time\n", |
|
|
743 |
"\n", |
|
|
744 |
"# Set up the Selenium WebDriver\n", |
|
|
745 |
"driver = webdriver.Chrome()\n", |
|
|
746 |
"\n", |
|
|
747 |
"# Navigate to the webpage\n", |
|
|
748 |
"driver.get('https://clinicaltrials.gov/study/NCT06626386?aggFilters=status:rec&rank=2#participation-criteria')\n", |
|
|
749 |
"\n", |
|
|
750 |
"# Wait for the Eligibility Criteria container to load\n", |
|
|
751 |
"try:\n", |
|
|
752 |
" eligibility_container = WebDriverWait(driver, 20).until(\n", |
|
|
753 |
" EC.visibility_of_element_located((By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]'))\n", |
|
|
754 |
" )\n", |
|
|
755 |
" \n", |
|
|
756 |
" print(\"Eligibility Criteria container loaded successfully.\")\n", |
|
|
757 |
" \n", |
|
|
758 |
" # Find and extract the headers (like \"Description\", \"Ages Eligible for Study\", etc.)\n", |
|
|
759 |
" headers = driver.find_elements(By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]//dt')\n", |
|
|
760 |
" \n", |
|
|
761 |
" # Find and extract the content corresponding to each header\n", |
|
|
762 |
" contents = driver.find_elements(By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]//dd')\n", |
|
|
763 |
" \n", |
|
|
764 |
" print(headers)\n", |
|
|
765 |
" print(contents)\n", |
|
|
766 |
" \n", |
|
|
767 |
" # Create a dictionary to store criteria dynamically\n", |
|
|
768 |
" criteria_data = {}\n", |
|
|
769 |
" \n", |
|
|
770 |
" # Loop over the headers and their respective contents\n", |
|
|
771 |
" for header, content in zip(headers, contents):\n", |
|
|
772 |
" header_text = header.text.strip() # Get the header text\n", |
|
|
773 |
" content_text = content.text.strip() # Get the corresponding content text\n", |
|
|
774 |
" \n", |
|
|
775 |
" # Store in dictionary\n", |
|
|
776 |
" criteria_data[header_text] = content_text\n", |
|
|
777 |
"\n", |
|
|
778 |
" # Dynamically generate formatted criteria text\n", |
|
|
779 |
" formatted_criteria = \"\"\n", |
|
|
780 |
" for header, content in criteria_data.items():\n", |
|
|
781 |
" formatted_criteria += f\"{header}: {content}\\n\\n\" # Add each header-content pair to the formatted string\n", |
|
|
782 |
"\n", |
|
|
783 |
" # Print the formatted output to verify\n", |
|
|
784 |
" print(formatted_criteria)\n", |
|
|
785 |
" \n", |
|
|
786 |
" # Save the output to a text file\n", |
|
|
787 |
" with open('eligibility_criteria_dynamic.txt', 'w') as file:\n", |
|
|
788 |
" file.write(formatted_criteria)\n", |
|
|
789 |
" \n", |
|
|
790 |
" print(\"Data successfully written to eligibility_criteria_dynamic.txt\")\n", |
|
|
791 |
" \n", |
|
|
792 |
"except Exception as e:\n", |
|
|
793 |
" print(\"An error occurred:\", e)\n", |
|
|
794 |
"\n", |
|
|
795 |
"finally:\n", |
|
|
796 |
" # Pause to visually inspect the browser\n", |
|
|
797 |
" time.sleep(5)\n", |
|
|
798 |
"\n", |
|
|
799 |
" # Close the browser\n", |
|
|
800 |
" driver.quit()\n" |
|
|
801 |
] |
|
|
802 |
}, |
|
|
803 |
{ |
|
|
804 |
"cell_type": "code", |
|
|
805 |
"execution_count": 6, |
|
|
806 |
"metadata": {}, |
|
|
807 |
"outputs": [ |
|
|
808 |
{ |
|
|
809 |
"name": "stdout", |
|
|
810 |
"output_type": "stream", |
|
|
811 |
"text": [ |
|
|
812 |
"Inclusion/Exclusion Criteria container loaded successfully.\n", |
|
|
813 |
"Inclusion/Exclusion Criteria:\n", |
|
|
814 |
"Description\n", |
|
|
815 |
"Inclusion Criteria:\n", |
|
|
816 |
"Men aged from 45 to 70 years\n", |
|
|
817 |
"Informed consent for PSA measurement for prostate cancer screening\n", |
|
|
818 |
"Exclusion Criteria:\n", |
|
|
819 |
"Patients unable to give consent\n", |
|
|
820 |
"Show less\n", |
|
|
821 |
"Study Population\n", |
|
|
822 |
"Male patients between the ages of 40 and 70 who receive a PSA test as part of their routine examination\n", |
|
|
823 |
"Other Criteria container loaded successfully.\n", |
|
|
824 |
"Other Criteria:\n", |
|
|
825 |
"Ages Eligible for Study\n", |
|
|
826 |
"45 Years to 70 Years (Adult, Older Adult )\n", |
|
|
827 |
"Sexes Eligible for Study\n", |
|
|
828 |
"Male\n", |
|
|
829 |
"Accepts Healthy Volunteers\n", |
|
|
830 |
"No\n", |
|
|
831 |
"Sampling Method\n", |
|
|
832 |
"Non-Probability Sample\n", |
|
|
833 |
"Data successfully written to clinical_trial_criteria.txt\n" |
|
|
834 |
] |
|
|
835 |
} |
|
|
836 |
], |
|
|
837 |
"source": [ |
|
|
838 |
"from selenium import webdriver\n", |
|
|
839 |
"from selenium.webdriver.common.by import By\n", |
|
|
840 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
841 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
842 |
"import time\n", |
|
|
843 |
"\n", |
|
|
844 |
"# Initialize the WebDriver (Make sure to specify the correct path to your chromedriver)\n", |
|
|
845 |
"driver = webdriver.Chrome()\n", |
|
|
846 |
"\n", |
|
|
847 |
"# Open the clinical trials page\n", |
|
|
848 |
"driver.get(\"https://clinicaltrials.gov/study/NCT06626386?aggFilters=status:rec&rank=2#participation-criteria\")\n", |
|
|
849 |
"\n", |
|
|
850 |
"# Wait for the page to load completely\n", |
|
|
851 |
"time.sleep(5)\n", |
|
|
852 |
"\n", |
|
|
853 |
"try:\n", |
|
|
854 |
" # Wait for the inclusion/exclusion criteria container to load\n", |
|
|
855 |
" inclusion_exclusion_criteria = WebDriverWait(driver, 20).until(\n", |
|
|
856 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]/div[1]'))\n", |
|
|
857 |
" )\n", |
|
|
858 |
" print(\"Inclusion/Exclusion Criteria container loaded successfully.\")\n", |
|
|
859 |
"\n", |
|
|
860 |
" # Scraping inclusion/exclusion criteria\n", |
|
|
861 |
" inclusion_exclusion_text = inclusion_exclusion_criteria.text\n", |
|
|
862 |
" print(\"Inclusion/Exclusion Criteria:\")\n", |
|
|
863 |
" print(inclusion_exclusion_text)\n", |
|
|
864 |
"\n", |
|
|
865 |
" # Wait for the other criteria container to load\n", |
|
|
866 |
" other_criteria = WebDriverWait(driver, 20).until(\n", |
|
|
867 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]/div[2]'))\n", |
|
|
868 |
" )\n", |
|
|
869 |
" print(\"Other Criteria container loaded successfully.\")\n", |
|
|
870 |
"\n", |
|
|
871 |
" # Scraping other criteria\n", |
|
|
872 |
" other_criteria_text = other_criteria.text\n", |
|
|
873 |
" print(\"Other Criteria:\")\n", |
|
|
874 |
" print(other_criteria_text)\n", |
|
|
875 |
"\n", |
|
|
876 |
" # Writing the scraped data to a text file\n", |
|
|
877 |
" with open('clinical_trial_criteria.txt', 'w') as file:\n", |
|
|
878 |
" file.write(\"Inclusion/Exclusion Criteria:\\n\")\n", |
|
|
879 |
" file.write(inclusion_exclusion_text + \"\\n\\n\")\n", |
|
|
880 |
" file.write(\"Other Criteria:\\n\")\n", |
|
|
881 |
" file.write(other_criteria_text)\n", |
|
|
882 |
"\n", |
|
|
883 |
" print(\"Data successfully written to clinical_trial_criteria.txt\")\n", |
|
|
884 |
"\n", |
|
|
885 |
"except Exception as e:\n", |
|
|
886 |
" print(f\"An error occurred: {str(e)}\")\n", |
|
|
887 |
"\n", |
|
|
888 |
"finally:\n", |
|
|
889 |
" # Optionally, keep the browser open to see the result\n", |
|
|
890 |
" time.sleep(10) # Adjust the sleep time as needed\n", |
|
|
891 |
"\n", |
|
|
892 |
" # Close the browser\n", |
|
|
893 |
" driver.quit()\n" |
|
|
894 |
] |
|
|
895 |
}, |
|
|
896 |
{ |
|
|
897 |
"cell_type": "code", |
|
|
898 |
"execution_count": 14, |
|
|
899 |
"metadata": {}, |
|
|
900 |
"outputs": [ |
|
|
901 |
{ |
|
|
902 |
"name": "stdout", |
|
|
903 |
"output_type": "stream", |
|
|
904 |
"text": [ |
|
|
905 |
"Inclusion Criteria element is now in view.\n", |
|
|
906 |
"Inclusion Criteria:\n", |
|
|
907 |
"Men aged from 45 to 70 years\n", |
|
|
908 |
"Informed consent for PSA measurement for prostate cancer screening\n", |
|
|
909 |
"Exclusion Criteria element is now in view.\n", |
|
|
910 |
"Exclusion Criteria:\n", |
|
|
911 |
"Patients unable to give consent\n", |
|
|
912 |
"Other Criteria container loaded successfully.\n", |
|
|
913 |
"Other Criteria:\n", |
|
|
914 |
"Ages Eligible for Study\n", |
|
|
915 |
"45 Years to 70 Years (Adult, Older Adult )\n", |
|
|
916 |
"Sexes Eligible for Study\n", |
|
|
917 |
"Male\n", |
|
|
918 |
"Accepts Healthy Volunteers\n", |
|
|
919 |
"No\n", |
|
|
920 |
"Sampling Method\n", |
|
|
921 |
"Non-Probability Sample\n", |
|
|
922 |
"Data successfully written to clinical_trial_criteria.txt\n" |
|
|
923 |
] |
|
|
924 |
} |
|
|
925 |
], |
|
|
926 |
"source": [ |
|
|
927 |
"from selenium import webdriver\n", |
|
|
928 |
"from selenium.webdriver.common.by import By\n", |
|
|
929 |
"from selenium.webdriver.support.ui import WebDriverWait\n", |
|
|
930 |
"from selenium.webdriver.support import expected_conditions as EC\n", |
|
|
931 |
"import time\n", |
|
|
932 |
"\n", |
|
|
933 |
"# Initialize the WebDriver (Make sure to specify the correct path to your chromedriver)\n", |
|
|
934 |
"driver = webdriver.Chrome()\n", |
|
|
935 |
"\n", |
|
|
936 |
"# Open the clinical trials page\n", |
|
|
937 |
"driver.get(\"https://clinicaltrials.gov/study/NCT06626386?aggFilters=status:rec&rank=2#participation-criteria\")\n", |
|
|
938 |
"\n", |
|
|
939 |
"# Wait for the page to load completely\n", |
|
|
940 |
"time.sleep(5)\n", |
|
|
941 |
"\n", |
|
|
942 |
"try:\n", |
|
|
943 |
" # Scroll the page to bring inclusion criteria into view\n", |
|
|
944 |
" inclusion_element = WebDriverWait(driver, 20).until(\n", |
|
|
945 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"eligibility-criteria-description\"]/div/div/ul[1]')) #//*[@id=\"eligibility-criteria-description\"]/div/div/ul[1]\n", |
|
|
946 |
" )\n", |
|
|
947 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", inclusion_element)\n", |
|
|
948 |
" print(\"Inclusion Criteria element is now in view.\")\n", |
|
|
949 |
"\n", |
|
|
950 |
" # Scraping inclusion criteria\n", |
|
|
951 |
" inclusion_criteria_text = inclusion_element.text\n", |
|
|
952 |
" print(\"Inclusion Criteria:\")\n", |
|
|
953 |
" print(inclusion_criteria_text)\n", |
|
|
954 |
"\n", |
|
|
955 |
" # Scroll to exclusion criteria\n", |
|
|
956 |
" exclusion_element = WebDriverWait(driver, 20).until(\n", |
|
|
957 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"eligibility-criteria-description\"]/div/div/ul[2]'))\n", |
|
|
958 |
" )\n", |
|
|
959 |
" driver.execute_script(\"arguments[0].scrollIntoView(true);\", exclusion_element)\n", |
|
|
960 |
" print(\"Exclusion Criteria element is now in view.\")\n", |
|
|
961 |
"\n", |
|
|
962 |
" # Scraping exclusion criteria\n", |
|
|
963 |
" exclusion_criteria_text = exclusion_element.text\n", |
|
|
964 |
" print(\"Exclusion Criteria:\")\n", |
|
|
965 |
" print(exclusion_criteria_text)\n", |
|
|
966 |
" \n", |
|
|
967 |
" other_criteria = WebDriverWait(driver, 20).until(\n", |
|
|
968 |
" EC.presence_of_element_located((By.XPATH, '//*[@id=\"participation-criteria\"]/ctg-participation-criteria/div[2]/div/div[2]/div[2]'))\n", |
|
|
969 |
" )\n", |
|
|
970 |
" print(\"Other Criteria container loaded successfully.\")\n", |
|
|
971 |
" \n", |
|
|
972 |
" other_criteria_text = other_criteria.text\n", |
|
|
973 |
" print(\"Other Criteria:\")\n", |
|
|
974 |
" print(other_criteria_text)\n", |
|
|
975 |
"\n", |
|
|
976 |
" # Writing the scraped data to a text file\n", |
|
|
977 |
" with open('clinical_trial_criteria.txt', 'w') as file:\n", |
|
|
978 |
" file.write(\"Inclusion Criteria:\\n\")\n", |
|
|
979 |
" file.write(inclusion_criteria_text + \"\\n\\n\")\n", |
|
|
980 |
" file.write(\"Exclusion Criteria:\\n\")\n", |
|
|
981 |
" file.write(exclusion_criteria_text + \"\\n\\n\")\n", |
|
|
982 |
" file.write(\"Other Criteria:\\n\")\n", |
|
|
983 |
" file.write(other_criteria_text)\n", |
|
|
984 |
"\n", |
|
|
985 |
" print(\"Data successfully written to clinical_trial_criteria.txt\")\n", |
|
|
986 |
"\n", |
|
|
987 |
"except Exception as e:\n", |
|
|
988 |
" print(f\"An error occurred: {str(e)}\")\n", |
|
|
989 |
"\n", |
|
|
990 |
"finally:\n", |
|
|
991 |
" # Optionally, keep the browser open to see the result\n", |
|
|
992 |
" time.sleep(5) # Adjust the sleep time as needed\n", |
|
|
993 |
"\n", |
|
|
994 |
" # Close the browser\n", |
|
|
995 |
" driver.quit()\n" |
|
|
996 |
] |
|
|
997 |
}, |
|
|
998 |
{ |
|
|
999 |
"cell_type": "code", |
|
|
1000 |
"execution_count": null, |
|
|
1001 |
"metadata": {}, |
|
|
1002 |
"outputs": [], |
|
|
1003 |
"source": [] |
|
|
1004 |
} |
|
|
1005 |
], |
|
|
1006 |
"metadata": { |
|
|
1007 |
"kernelspec": { |
|
|
1008 |
"display_name": "Scraping Environment", |
|
|
1009 |
"language": "python", |
|
|
1010 |
"name": "scraping_env" |
|
|
1011 |
}, |
|
|
1012 |
"language_info": { |
|
|
1013 |
"codemirror_mode": { |
|
|
1014 |
"name": "ipython", |
|
|
1015 |
"version": 3 |
|
|
1016 |
}, |
|
|
1017 |
"file_extension": ".py", |
|
|
1018 |
"mimetype": "text/x-python", |
|
|
1019 |
"name": "python", |
|
|
1020 |
"nbconvert_exporter": "python", |
|
|
1021 |
"pygments_lexer": "ipython3", |
|
|
1022 |
"version": "3.9.19" |
|
|
1023 |
} |
|
|
1024 |
}, |
|
|
1025 |
"nbformat": 4, |
|
|
1026 |
"nbformat_minor": 2 |
|
|
1027 |
} |