-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebscraping_dissertações_ppgp.py
More file actions
72 lines (53 loc) · 2.08 KB
/
webscraping_dissertações_ppgp.py
File metadata and controls
72 lines (53 loc) · 2.08 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
# -*- coding: utf-8 -*-
"""Webscraping - Dissertações PPGP.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1rIOAXG3aOQ1KdpeK2YmEht0irsERWFU7
"""
from types import NoneType
import requests
from bs4 import BeautifulSoup
import pandas as pd
from google.colab import files
# Fazer a requisição HTTP
url = 'http://repositorio.uninove.br/xmlui/handle/123456789/37/browse?order=ASC&rpp=20&sort_by=1&etal=-1&offset=0&type=title'
pags = [] # lista de páginas
for offset in range(0,161,20):
urlpagpre = url.split("offset=")[0] + "offset="
urlpag = urlpagpre + str(offset)
pags.append(urlpag)
refs = [] # lista de referencia dos artigos
for p in pags:
response = requests.get(p)
# Analisar o conteúdo HTML da página
soup = BeautifulSoup(response.text, 'html.parser')
container = soup.find(class_='ds-artifact-list')
# Encontrar todos os elementos 'a' dentro do container
links = container.find_all('a')
# Extrair os URLs dos links encontrados
for link in links:
refs.append(link['href'])
artifacts = [] # lista de url dos artigos
for ref in refs:
urlartpre = url.split("/xmlui")[0]
urlart = urlartpre + ref
artifacts.append(urlart)
df = pd.DataFrame(columns=['titulo', 'autor', 'data', 'resumo'])
for artigo in artifacts:
response1 = requests.get(artigo)
soup1 = BeautifulSoup(response1.text, 'html.parser')
titulo = soup1.find('h1').text
autor = soup1.find(class_='simple-item-view-authors').text[1:-1]
data = soup1.find_all(class_='simple-item-view-other')[1].text[7:-1]
if soup1.find(class_='simple-item-view-description') == None:
resumo = None
else:
resumo = soup1.find(class_='simple-item-view-description').text[11:-1]
dados = pd.DataFrame({'titulo': [titulo],
'autor': [autor],
'data': [data],
'resumo': [resumo]})
df = pd.concat([df, dados], ignore_index=True)
nome_arquivo = 'Dissertações PPGP.xlsx'
df.to_excel(nome_arquivo, index=False)
files.download(nome_arquivo)