-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrape.py
199 lines (165 loc) · 6.18 KB
/
scrape.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
import requests
import pandas as pd
from splinter import Browser
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager
import time
import re
def striphtml(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
def scrape():
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=True)
url = "https://philpapers.org/browse/top-level-ontologies?limit=50&newWindow=&publishedOnly=&freeOnly=&catq=barry+smith&hideAbstracts=&langFilter=&filterByAreas=&sqc=&proOnly=on&uncat=&cn=top-level-ontologies&onlineOnly=&cId=492826&categorizerOn=&new=1&start=0&setAside=&sort=pubYear&showCategories=on&format=html&jlist=&ap_c1=&ap_c2="
browser.visit(url)
time.sleep(1)
html = browser.html
soup = BeautifulSoup(html, "html.parser")
full_citation_list = soup.find_all("span", class_="citation")
html = []
for i in range(len(full_citation_list)):
html.append(full_citation_list[i])
author_full = []
titles = []
pub_date = []
pub_info = []
links = []
authors = []
titles_full = []
pub_info_full = []
for entry in html:
author_full.append(entry.find_all("span", class_="name"))
titles_full.append(entry.find("span", class_="articleTitle").text)
pub_date.append(entry.find("span", class_="pubYear").text)
pub_info_full.append(entry.find("span", class_="pubInfo").text)
link = entry.find("a", href=True)
links.append("https://philpapers.org" + link["href"])
for i in range(len(pub_info_full)):
line = pub_info_full[i]
line = line.replace('.','')
pub_info.append(line)
i += 1
for i in range(len(titles_full)):
line = titles_full[i]
line = line.replace('.','')
titles.append(line)
i += 1
author_full = list(map(str, author_full))
for i in range(len(author_full)):
line = striphtml(author_full[i])
#line = line.replace(', ', ',')
line = line.replace(' ]', ']')
authors.append(line)
i += 1
for i in range(len(authors)):
authors[i] = authors[i].strip('][').split(',')
phil_authors = []
phil_titles = []
phil_pub_date = []
phil_pub_info = []
phil_links = []
phil_authors = authors
phil_titles = titles
phil_pub_date = pub_date
phil_pub_info = pub_info
phil_links = links
# entries = []
# for publication in range(len(titles)):
# case = {"author": authors[publication], "title": titles[publication], "pub_date": pub_date[publication],
# "pub_info": pub_info[publication], "links": links[publication]}
# entries.append(case)
browser.quit()
time.sleep(1)
#start of scilit scraper
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=True)
url = "https://www.scilit.net/articles/search?facets__language%5B0%5D=English&highlight=1&q=%22basic%20formal%20ontology%22&sort=Newest&nb_articles=500"
browser.visit(url)
time.sleep(1)
html = browser.html
soup = BeautifulSoup(html, "html.parser")
full_citation_list = soup.find_all("div", class_="result")
html = []
for i in range(len(full_citation_list)):
html.append(full_citation_list[i])
authors = []
titles = []
titles_full = []
pub_date = []
pub_info = []
links = []
author_full = []
pub_date_full = []
pub_info_full = []
links_full = []
for entry in html:
author_full.append(entry.find_all("div", class_="authors"))
titles_full.append(entry.find("div", class_="title").text)
pub_date_full.append(entry.find("div", class_="pubdate").text)
pub_info_full.append(entry.find("div", class_="publisher"))
#links.append(entry.find("div", class_="doilink"))
link = entry.find("a", href=True)
links_full.append(link)
for i in range(len(links_full)):
link = links_full[i]["href"]
links.append("https://www.scilit.net"+ link)
i =+ 1
pub_info_full = list(map(str, pub_info_full))
for i in range(len(pub_info_full)):
line = striphtml(pub_info_full[i])
line = line.replace('by\n', '')
line = line.replace('\n', '')
pub_info.append(line)
i += 1
for i in range(len(pub_date_full)):
line = pub_date_full[i]
line = line.replace('Published: ', '')
pub_date.append(line)
i += 1
for i in range(len(pub_date)):
if pub_date[i] == "unknown date":
pub_date[i] = "0 - Date Unknown"
i += 1
else:
pub_date[i] = pub_date[i][-4:]
i += 1
for i in range(len(titles_full)):
line = titles_full[i]
line = line.replace('\n', '')
titles.append(line)
i += 1
author_full = list(map(str, author_full))
for i in range(len(author_full)):
line = striphtml(author_full[i])
line = line.replace('\n', '')
line = line.replace(' ]', ']')
line = line.replace(',',', ')
authors.append(line)
i += 1
for i in range(len(authors)):
authors[i] = authors[i].strip('][').split(',')
for x in phil_authors:
authors.append(x)
for x in phil_titles:
titles.append(x)
for x in phil_pub_date:
pub_date.append(x)
for x in phil_pub_info:
pub_info.append(x)
for x in phil_links:
links.append(x)
articles = {}
articles["Authors"] = authors
articles["Title"] = titles
articles["Date"] = pub_date
articles["Publication"] = pub_info
articles["Link"] = links
# for publication in range(len(titles)):
# case = {"author": authors[publication], "title": titles[publication], "pub_date": pub_date[publication],
# "pub_info": pub_info[publication], "links": links[publication]}
# entries.append(case)
browser.quit()
# print(f"length of entries list is: {len(entries)}")
# print(entries)
return articles