Skip to content

Commit 4120d95

Browse files
committed
WebScrap
1 parent 383f540 commit 4120d95

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

.idea/PythonScripts.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CompactarArquivos/compacta.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from zipfile import ZipFile
2+
import os
3+
4+
# Para caminhos com barra invertida (\), utilize r
5+
caminho = r'caminho'
6+
7+
# ESCREVE
8+
with ZipFile('arquivos.zip', 'w') as zip:
9+
for arquivo in os.listdir(caminho):
10+
caminho_completo = os.path.join(caminho, arquivo)
11+
zip.write(caminho_completo, arquivo)
12+
13+
# LISTA
14+
with ZipFile('arquivos.zip', 'r') as zip:
15+
for arquivo in zip.namelist():
16+
print(arquivo)
17+
18+
# EXTRAI
19+
with ZipFile('arquivos.zip', 'r') as zip:
20+
zip.extractall('descompactado')

WebScraping/Scrap1.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
from bs4 import BeautifulSoup
3+
import requests
4+
5+
url ='https://pt.stackoverflow.com/questions/tagged/python'
6+
7+
8+
response = requests.get(url)
9+
10+
11+
#print(response.text)
12+
13+
contador = 0
14+
#passando o HTML para o BeautifulSoup
15+
html = BeautifulSoup(response.text, 'html.parser')
16+
for pergunta in html.select('.s-post-summary--content'):
17+
titulo = pergunta.select_one('.s-post-summary--content-title').text
18+
data = pergunta.select_one('.relativetime').text
19+
print(titulo)
20+
print(data)
21+
if data == 'ontem':
22+
contador += 1
23+
24+
25+
print("Perguntas criadas a ontem " + str(contador))
26+
27+

0 commit comments

Comments
 (0)