Code Monkey home page Code Monkey logo

Comments (10)

slukin1 avatar slukin1 commented on May 29, 2024 1
import websocket
websocket.enableTrace(True)
headers = json.dumps({'Origin': 'https://data.tradingview.com'})
ws = websocket.create_connection('wss://data.tradingview.com/socket.io/websocket?&type=chart',headers=headers)
#result = ws.recv()
#print(result)
while True:
    ws.recv()

from tradingview-scraper.

0xrushi avatar 0xrushi commented on May 29, 2024

Thanks @euvgub !! :)

from tradingview-scraper.

madanmohan0507 avatar madanmohan0507 commented on May 29, 2024

@euvgub @0xrushi Hi,
I tried using this function and it keeps on giving me either
File c:\users\asus\trading\data fetcher.py:38 in get_auth_token
auth_token = response.json()['user']['auth_token']

KeyError: 'user'

or
m45m{"m":"protocol_error","p":["bad auth token"]}

I don't know why this is happening though. Could you please help me out.

P.S.: Turns out there is a reCAPTCHA verification there which is failing. Please let me know how we can bypass the verification.

Thanks

from tradingview-scraper.

daltas avatar daltas commented on May 29, 2024

Hi, I also have same debug error as above,

auth_token = response.json()['user']['auth_token']
~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'user'

i'm not using CAPTCHA when i logging on,

It would be very helpful someone who rescue me....
Thanks

from tradingview-scraper.

madanmohan0507 avatar madanmohan0507 commented on May 29, 2024

@daltas Hey, there is a discussion about the same in the create study issue. I was able to resolve it thanks to @slukin1. You can check the same solution out. :)

from tradingview-scraper.

slukin1 avatar slukin1 commented on May 29, 2024

No recapcha if use Chrome DevTools Protocol for receiving auth_token
I`m in progress how to get cookie value sessionid or auth_token from received page or headers after log in

import json
import time
import subprocess
import requests
import websocket
from websocket import create_connection
websocket.enableTrace(True)
def start_browser(browser_path, debugging_port):
    options = [#'--headless',
                f'--remote-debugging-port={debugging_port}',
               #'--remote-allow-origins=http://127.0.0.1:{debugging_port}']
               '--remote-allow-origins=*']              
    browser_proc = subprocess.Popen([browser_path] + options)
    wait_seconds = 10.0
    sleep_step = 0.25
    while wait_seconds > 0:
        try:
            url = f'http://127.0.0.1:{debugging_port}/json'
            time.sleep(5)
            resp = requests.get(url).json()
            ws_url = resp[0]['webSocketDebuggerUrl']
            return browser_proc, create_connection(ws_url) 
        except requests.exceptions.ConnectionError:
            time.sleep(sleep_step)
            wait_seconds -= sleep_step
    raise Exception('Unable to connect to chrome')
request_id = 0
def run_command(conn, method, **kwargs):
    global request_id
    request_id += 1
    command = {'method': method,
               'id': request_id,
               'params': kwargs}
    conn.send(json.dumps(command))
    while True:
        msg = json.loads(conn.recv())
        if msg.get('id') == request_id:
            return msg
tv_url = 'https://tradingview.com'
#browser_path = '/usr/bin/google-chrome'
#browser_path = '/usr/bin/google-chrome-beta'
browser_path = '/usr/bin/google-chrome-unstable'
#browser_path = '/usr/bin/microsoft-edge'
#browser_path = '/snap/bin/chromium'
#browser_path = '/usr/bin/firefox'
browser, conn = start_browser(browser_path, 9222)
run_command(conn, 'Page.navigate', url=tv_url)
time.sleep(5) # let it load
js = """
var step1 = document.evaluate('//button[@aria-label="Open user menu"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
step1.click();
var step2 = document.evaluate('//button[@data-name="header-user-menu-sign-in"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
step2.click();
setTimeout(function(){
    document.getElementById("id_username").focus();
    document.getElementById("id_username").value = "your_login";

    document.getElementById("id_password").focus();
    document.getElementById("id_password").value = "your_password";
    var signin = document.evaluate('//button[contains(@class,"submitButton")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    signin.focus(); 
    signin.click(); 
},500);
"""
result = run_command(conn, 'Runtime.evaluate', expression=js)
print(result)
browser.terminate()

from tradingview-scraper.

daltas avatar daltas commented on May 29, 2024

@daltas Hey, there is a discussion about the same in the create study issue. I was able to resolve it thanks to @slukin1. You can check the same solution out. :)

Hi, Congraci the success frend!! I'm still in the deep err sea :)

from tradingview-scraper.

daltas avatar daltas commented on May 29, 2024

@slukin1 Thanks a lot! i got a handshake 400 error, can you guess why?

status, resp = _get_resp_headers(sock)

raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request

from tradingview-scraper.

daltas avatar daltas commented on May 29, 2024

hi @slukin1 Great Thanx!
maybe there is a problem in an unexpected place.... ;)

from tradingview-scraper.

slukin1 avatar slukin1 commented on May 29, 2024

websocket.enableTrace(True) and You`ll receive more information about the reason for the failure
raise WebSocketBadStatusException("Handshake status {status} {message} -+-+- {headers} -+-+- {body}".format(status=status, message=status_message, headers=resp_headers, body=response_body), status, status_message, resp_headers, response_body)

from tradingview-scraper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.