-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_html_dolarhoy.py
48 lines (38 loc) · 2.12 KB
/
scrape_html_dolarhoy.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
import requests
from bs4 import BeautifulSoup
import pprint # solo para presentar la info del dictionary resultado en el terminal
# resDolarHoy = requests.get('https://www.dolarhoy.com/')
resDolarOficial = requests.get('https://www.dolarhoy.com/cotizaciondolaroficial')
resDolarBlue = requests.get('https://www.dolarhoy.com/cotizaciondolarblue')
# soupDolarHoy = BeautifulSoup(resDolarHoy.text, 'html.parser')
soupDolarOficial = BeautifulSoup(resDolarOficial.text, 'html.parser')
soupDolarBlue = BeautifulSoup(resDolarBlue.text, 'html.parser')
message = ''
# print('***** Dolar Oficial *****')
# for info in soupDolarOficial.select('.pull-left'):
# print(info.text)
# print('***** Dolar Blue *****')
# for info in soupDolarBlue.select('.pull-left'):
# print(info.text)
# soupDolarOficial.find_all(attrs={"class": "topic"})
# soupDolarOficial.find_all(attrs={"class": "value"})
message = f"{message} Dolar Oficial:"
oficialCompraTitulo = soupDolarOficial.find_all(attrs={"class": "topic"})[0]
oficialCompraValor = soupDolarOficial.find_all(attrs={"class": "value"})[0]
message = f"{message}\n-----------------------\n{oficialCompraTitulo}\n{oficialCompraValor}\n"
oficialCompraTitulo = soupDolarOficial.find_all(attrs={"class": "topic"})[1]
oficialCompraValor = soupDolarOficial.find_all(attrs={"class": "value"})[1]
message = f"{message}\n-----------------------\n{oficialCompraTitulo}\n{oficialCompraValor}\n"
# for info in soupDolarOficial.select('.pull-left'):
# message = message + ' | ' + info.text
message = f'{message}\nDolar Blue'
blueCompraTitulo = soupDolarBlue.find_all(attrs={"class": "topic"})[0]
blueCompraValor = soupDolarBlue.find_all(attrs={"class": "value"})[0]
message = f"{message}\n-----------------------\n{blueCompraTitulo}\n{blueCompraValor}\n"
blueCompraTitulo = soupDolarBlue.find_all(attrs={"class": "topic"})[1]
blueCompraValor = soupDolarBlue.find_all(attrs={"class": "value"})[1]
message = f"{message}\n-----------------------\n{blueCompraTitulo}\n{blueCompraValor}\n"
# for info in soupDolarBlue.select('.pull-left'):
# message = message + ' | ' + info.text
def getDolarCurrentQuote():
return message