-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathscrape.py
More file actions
47 lines (36 loc) · 1.74 KB
/
Copy pathscrape.py
File metadata and controls
47 lines (36 loc) · 1.74 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
# scrape the cvpr2019oar.html file looking for authors names, titles, and bib
# and create a database of all papers. This is necessary because
# extracting the authors, titles, and bib from PDFs directly is tricky.
import pickle
html = open('cvpr2019oar.html').read()
outdict = {}
while html.find('class="bibref"') != -1:
# defining id as the pdf url to remain consistent with other sections
# also removing '_CVPR_2019_paper.pdf' from each id
paperid = html[:html.find('class="bibref"')]
# checks for supplemental material
# empty string if no supp, url to supp if there is supp
supp = ''
if 'supplemental' in paperid[paperid.rfind('paper.pdf'):]:
supp = paperid[paperid.rfind('paper.pdf'):]
supp = supp[supp.find('href'):]
supp = supp[supp.find('"') + 1:supp.find('.pdf') + 4]
paperid = paperid[:paperid.rfind('paper.pdf')]
paperid = paperid[paperid.rfind('/')+1:-11]
# used to get each of the titles and authors of the text
bib = html[html.find('class="bibref"'):]
bib = bib[bib.find('>') + 1:bib.find('</div>')].strip() \
.replace('\n', '\n ') \
.replace(' }', '}')
# find the authors name and format with 'first last, first last, ...'
authors = bib[bib.find('author'):]
authors = authors[authors.find('{')+1:authors.find('}')].split(' and ')
authors = ', '.join([n[n.find(', ')+2:] + ' ' + n[:n.find(',')] for n in authors])
# title from bibtex
title = bib[bib.find('title'):]
title = title[title.find('{')+1:title.find('}')].strip()
# save each entry into a dictionary
outdict[paperid] = (title, authors, bib, supp)
html = html[html.find('class="bibref"') + 1:]
# dump a dictionary indexed by paper id that points to (title, authors) tuple
pickle.dump(outdict, open("papers.p", "wb"))