-
Notifications
You must be signed in to change notification settings - Fork 3
/
infos_paper.py
78 lines (75 loc) · 3.2 KB
/
infos_paper.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
from bs4 import BeautifulSoup
import os
import re
import wget
def get_links(paper, event_folder, title, previous_link):
"""Encontrar o link e realizar o download do PDF."""
try:
link_pdf = paper.find('a',href=re.compile(r'(.pdf)'))
link = link_pdf['href']
if not link in previous_link:
previous_link = link
if link.startswith('https://'):
full_link = link
full_name = os.path.join(event_folder, title.replace(' ','_') + '.pdf')
else:
full_link = "https://anpuh.org.br" + link
change = ['"', '*', ':', '<', '>', '?', '/', "\\", '|' , '_' , '@' , '+', '...']
for x in change:
title = title.replace(x, '')
full_name = os.path.join(event_folder, title.replace(' ','_') + '.pdf')
if not os.path.exists(full_name):
print('Salvando o pdf na pasta...\n')
try:
wget.download(full_link, out=full_name)
except Exception as e:
print(e)
else:
print("Arquivo já existe.\n")
else:
print("PDF desse paper é igual ao do paper anterior.\n")
except Exception as e:
print(e)
link = paper.find('a', href=re.compile(r'(.pdf)'))
link = None
print('Paper sem pdf disponível para download.\n')
def get_infos(paper_boxes, base_url, final_list, event_folder, previous_link):
"""Raspa as informações de cada paper."""
for paper in paper_boxes:
title = paper.h2.text
title = title.strip().lower().replace('/','-')
infos = paper.find_all('dt')
tipo = ""
event = ""
year = ""
authors = ""
file_link = ""
for info in infos:
if info.text.strip() == "Tipo":
tipo = info.find_next_sibling().text.strip()
print (f"Tipo : {tipo}")
if info.text.strip() == "Evento":
event = info.find_next_sibling().text.strip()
print (f"Evento : {event}")
if info.text.strip() == "Ano":
year = info.find_next_sibling().text.strip()
print (f"Ano : {year}")
if info.text.strip() == "Arquivo":
file_tag = info.find_next_sibling().a['href']
file_link = base_url + file_tag
print (f"Arquivo : {file_link}")
if info.text.strip() == "PDF LINK":
file_tag = info.find_next_sibling().a['href']
if file_tag.startswith('https://') == True:
file_link = file_tag
print (f"Arquivo : {file_link}")
else:
file_link = base_url + file_tag
print (f"Arquivo : {file_link}")
if info.text.strip() == "Autor(es)":
authors = info.find_next_sibling().text.strip()
print (f"\nAutor(es) : {authors}")
info_list = [authors, title, tipo, event, year, file_link]
final_list.append(info_list)
print('Encontrando link do paper...')
get_links(paper, event_folder, title, previous_link)