-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeb_Scraper.py
More file actions
181 lines (167 loc) · 6.24 KB
/
Web_Scraper.py
File metadata and controls
181 lines (167 loc) · 6.24 KB
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
"""# -*- coding: utf-8 -*-
@Info: Selenium Based Web Crawler capable of capturing Recent Journals in PDF format given the keywords.
The captured PDF is then ready for processing to scrape Required information from it.
@Dated: 17th Oct, 2019
@Authors: Asif Nawaz
"""
import csv
from sys import argv
#import parameters
from parsel import Selector
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
#script, keyword = argv
keyword = "Computer Vision"
path = str(r"D:\chromedriver_win32\chromedriver.exe")
driver = webdriver.Chrome(path)
################################################################################
# ACM Scraping Section
################################################################################
driver.get("https://scholar.google.com/")
sleep(3)
search_query = driver.find_element_by_xpath('//*[@id="gs_hdr_tsi"]')
try:
search_query.send_keys("site:dl.acm.org AND " + keyword)
sleep(0.5)
search_query.send_keys(Keys.RETURN)
sleep(1)
except:
print("NO SUBJECT FOUND!")
driver.quit()
search_results_page = Selector(text=driver.page_source)
links = search_results_page.xpath('//h3/a/@href').extract()
print(links)
sleep(1)
for link in links:
if "https://dl.acm.org/" in link:
driver.get(link)
sleep(0.5)
try:
print("Hello sir, gotcha")
response_page = Selector(text=driver.page_source)
pdf_link = response_page.xpath('//*[@id="divmain"]/table/tbody/tr/td[1]/table[1]/tbody/tr/td[2]/a/@href').extract_first()
pdf_link = 'https://dl.acm.org/'+pdf_link
driver.get(pdf_link)
sleep(0.5)
except:
print("PDF LINK NOT FOUND, VISITING NEXT PAGE.")
sleep(0.5)
else:
print("No results in the given domain")
#print("Links Browsed: ")
#print(links)
################################################################################
""" One Domain: "https://dl.acm.org/" crawled and TOP 10 results captured."""
################################################################################
# IEEE SCRAPING SECTION
################################################################################
driver.get("https://scholar.google.com/")
sleep(3)
search_query = driver.find_element_by_xpath('//*[@id="gs_hdr_tsi"]')
try:
search_query.send_keys("site:ieee.org AND " + keyword)
sleep(0.5)
search_query.send_keys(Keys.RETURN)
sleep(1)
except:
print("NO SUBJECT FOUND!")
driver.quit()
search_results_page = Selector(text=driver.page_source)
links = search_results_page.xpath('//h3/a/@href').extract()
print(links)
sleep(1)
for link in links:
if "https://ieeexplore.ieee.org/" in link:
driver.get(link)
sleep(0.5)
try:
print("Hello sir, gotcha")
response_page = Selector(text=driver.page_source)
pdf_link = response_page.xpath('//*[@id="LayoutWrapper"]/div/div/div/div[5]/div[2]/xpl-root/xpl-document-details/div/div[1]/div/div[2]/xpl-left-side-bar/div/div/ul/li[1]/a/@href').extract_first()
pdf_link = 'https://ieeexplore.ieee.org/'+pdf_link
driver.get(pdf_link)
sleep(0.5)
except:
print("PDF LINK NOT FOUND, VISITING NEXT PAGE.")
sleep(0.5)
else:
print("No results in the given domain")
print("Links Browsed: ")
print(links)
################################################################################
"""One Domain: "https://ieeexplore.ieee.org/" crawled and TOP 10 results captured."""
################################################################################
# SPRINGER Journals Scraping Section
################################################################################
"""
driver.get("https://scholar.google.com/")
sleep(3)
search_query = driver.find_element_by_xpath('//*[@id="gs_hdr_tsi"]')
try:
search_query.send_keys("site:springer.com AND " + keyword)
sleep(0.5)
search_query.send_keys(Keys.RETURN)
sleep(1)
except:
print("NO SUBJECT FOUND!")
driver.quit()
search_results_page = Selector(text=driver.page_source)
links = search_results_page.xpath('//h3/a/@href').extract()
print(links)
sleep(1)
for link in links:
if "https://link.springer.com/" in link:
driver.get(link)
sleep(0.5)
try:
print("Hello sir, gotcha")
download_button = driver.find_element_by_xpath('//*[@id="download"]')
download_button.click()
sleep(0.5)
except:
print("PDF LINK NOT FOUND, VISITING NEXT PAGE.")
sleep(0.5)
else:
print("No results in the given domain")
print("Links Browsed: ")
print(links)
"""
################################################################################
"""One Domain: "https://ieeexplore.ieee.org/" crawled and TOP 10 results captured."""
################################################################################
# ScienceDirect Scraping Section
################################################################################
driver.get("https://scholar.google.com/")
sleep(3)
search_query = driver.find_element_by_xpath('//*[@id="gs_hdr_tsi"]')
try:
search_query.send_keys("site:sciencedirect.com AND " + keyword)
sleep(0.5)
search_query.send_keys(Keys.RETURN)
sleep(1)
except:
print("NO SUBJECT FOUND!")
driver.quit()
search_results_page = Selector(text=driver.page_source)
links = search_results_page.xpath('//h3/a/@href').extract()
print(links)
sleep(1)
for link in links:
if "sciencedirect.com" in link:
driver.get(link)
sleep(0.5)
try:
print("Hello sir, gotcha")
response_page = Selector(text=driver.page_source)
pdf_link = response_page.xpath('').extract_first()
pdf_link = 'https:///'+pdf_link
driver.get(pdf_link)
sleep(0.5)
except:
print("PDF LINK NOT FOUND, VISITING NEXT PAGE.")
sleep(0.5)
else:
print("No results in the given domain")
print("Links Browsed: ")
print(links)