Ir para conteúdo
Fórum Script Brasil
  • 0

Python+Selenium+Csv


Gabriel Vitor da Silva

Pergunta

Alguém pode me ajudar nesse exercício?

Get specific data - “Date” and “Close” - for the past 10 days from Yahoo Finance and save ito n a CSV file, named “eur_btc_rates.csv”, with two columns - “Date” and “BTC Closing Value”.

Link to Yahoo rates:

https://finance.yahoo.com/quote/BTC-EUR/history/

 

 

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Olá, não sei se precisa ainda...mas consegui resolver desta maneira aqui:

from selenium import webdriver
import csv


driver = webdriver.Chrome(executable_path='C:\webdrivers\chromedriver.exe')
driver.get('https://finance.yahoo.com/quote/BTC-EUR/history/')


tabela1 = driver.find_element_by_xpath('//td[@class="Py(10px) Ta(start) Pend(10px)"]')
fechamento1 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[1]/td[5]')

tabela2 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[2]/td[1]')
fechamento2 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[2]/td[5]')

tabela3 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[3]/td[1]')
fechamento3 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[3]/td[5]')

tabela4 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[4]/td[1]')
fechamento4 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[4]/td[5]')

tabela5 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[5]/td[1]')
fechamento5 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[5]/td[5]')

tabela6 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[6]/td[1]')
fechamento6 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[6]/td[5]')

tabela7 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[7]/td[1]')
fechamento7 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[7]/td[5]')

tabela8 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[8]/td[1]')
fechamento8 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[8]/td[5]')

tabela9 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[9]/td[1]')
fechamento9 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[9]/td[5]')

tabela10 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[10]/td[1]')
fechamento10 = driver.find_element_by_xpath('//*[@id="Col1-1-HistoricalDataTable-Proxy"]/section/div[2]/table/tbody/tr[10]/td[5]')


f = open('eur_btc_rates.csv', 'a', newline="")
tabelaMain = ('Date', 'BTC Closing Value')
t1 = (tabela1.text, fechamento1.text)
t2 = (tabela2.text, fechamento2.text)
t3 = (tabela3.text, fechamento3.text)
t4 = (tabela4.text, fechamento4.text)
t5 = (tabela5.text, fechamento5.text)
t6 = (tabela6.text, fechamento6.text)
t7 = (tabela7.text, fechamento7.text)
t8 = (tabela8.text, fechamento8.text)
t9 = (tabela9.text, fechamento9.text)
t10 = (tabela10.text, fechamento10.text)


writer = csv.writer(f)
writer.writerow(tabelaMain)
writer.writerow(t1)
writer.writerow(t2)
writer.writerow(t3)
writer.writerow(t4)
writer.writerow(t5)
writer.writerow(t6)
writer.writerow(t7)
writer.writerow(t8)
writer.writerow(t9)
writer.writerow(t10)

f.close()
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...