-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpegand_dados_tradingview.py
85 lines (67 loc) · 2.63 KB
/
pegand_dados_tradingview.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""Pegando dados do tradingview.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1QjtnKnEi1abdvKpgWz3RS0HAMCI_bkpJ
"""
#install chromium, its driver, and selenium:
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
#set options to be headless
url=('https://medium.com/@darektidwell1980/using-selenium-with-google-colaboratory-ca4a4f21021f')
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('-headless')
options.add_argument('-no-sandbox')
options.add_argument('-disable-dev-shm-usage')
#open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get(url)
print(wd.page_source) # results
from selenium import webdriver
import time
import pandas as pd
import datetime
from google.colab import drive
drive.mount('/drive')
df=[]
df=pd.DataFrame(df)
df.to_csv('/drive/My Drive/trade/indice.csv')
#import pandas as pd
driver = webdriver.Chrome('chromedriver',options=options)
# Remember the ChromeDriver File? You have to tell the code where that
# file is located here.
#driver.get('https://br.tradingview.com/symbols/EURUSD/?exchange=FX_IDC')
driver.get('https://br.tradingview.com/symbols/EURGBP/?exchange=OANDA')
#print(driver.find_elements_by_xpath('//*[@id="anchor-page-1"]/div/div[3]/div[1]/div/div/div/div[1]/div[1]')[0].text)
# This is the link of the webpage.
tempo=1
data=[]
#for i in range(1,100):
# time.sleep(tempo)
# data.append(driver.find_elements_by_xpath('//*[@id="anchor-page-1"]/div/div[3]/div[1]/div/div/div/div[1]/div[1]')[0].text)
# WARNING:
# Executing these lines of code will already open the webpage on Chrome.
def brigas(data):
data = pd.read_csv(caminho,index_col=None)
data.columns=['Preço']
zona=data.groupby(["Preço"])['Preço'].count().sort_values(ascending=False).iloc[0:30]
zonas=data.groupby(["Preço"])['Preço'].count().sort_values(ascending=False).iloc[0:30].plot(kind='bar',figsize=(30,30),title="Zonas de briga")
return zona
comand=True
while comand:
time.sleep(tempo)
price=[]
col=[]
time_stamp= datetime.datetime.now()
time_stamp=time_stamp.strftime("%Y %m %d %H:%M:%S")
price.append(driver.find_elements_by_xpath('//*[@id="anchor-page-1"]/div/div[3]/div[1]/div/div/div/div[1]/div[1]')[0].text)
col=[time_stamp]
col.extend(price)
df=pd.DataFrame(col)
df=df.T
df.to_csv('/drive/My Drive/trade/novo.csv',mode='a',header= False)
print(col)
caminho=('/drive/My Drive/trade/novo.csv')
dados_briga=brigas(data,caminho)