Last active
December 18, 2019 18:38
-
-
Save luxu/06f7862cca2d79119e9912ee91c8badc to your computer and use it in GitHub Desktop.
site Valor da Globo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from bs4 import BeautifulSoup | |
| import win32com.client as win32 | |
| from requests import get | |
| import lxml.html | |
| from pprint import pprint | |
| url = 'https://valor.globo.com/' | |
| # html = urlopen(url) | |
| response = get(url) | |
| html = response.text | |
| soup = lxml.html.fromstring(html) | |
| bs = BeautifulSoup(html, 'lxml') | |
| tabela = bs.select('section-data_table tr') | |
| tr = bs.find_all('tr') | |
| soup.xpath('//section[@class="section-data"][2]/div[2]//table//tbody//tr/td/text()') | |
| for r in soup.xpath('//section[@class="section-data"][2]/div[2]//table'): | |
| cabecalho = r.xpath('thead//tr//th//text()') | |
| for i in r.xpath('tbody//tr'): | |
| linha = ''.join(str(i.xpath('td/text()')).split(',')) | |
| if 'Dólar' in linha: | |
| name = linha.split("'")[1] | |
| compra = linha.split("'")[3] | |
| venda = linha.split("'")[5] | |
| variacao = linha.split("'")[7] | |
| pprint(f"{name}.: COMPRA: {compra} - VENDA: {venda} - VARIAÇÃO: {variacao}") | |
| # dolarc = tr[1].text | |
| # dolart = tr[2].text | |
| # valorc = tr[3].text | |
| # | |
| # dolar1 = [] | |
| # dolar2 = [] | |
| # valor1 = [] | |
| # | |
| # for tabela in tabela: | |
| # dolar1 = dolarc.contents[1] | |
| # dolar2 = dolart.contents[2] | |
| # valorc = dolart.contents[0] | |
| # df = pd.DataFrame({"Dolar Comercial": compra,"Dolar Turismo":venda,}) | |
| # print(df.head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment