finviz icon indicating copy to clipboard operation
finviz copied to clipboard

Using Screener Functionality with Finviz Elite Account

Open NimaMPH opened this issue 4 years ago • 5 comments

Hi There,

How can I use screener with Finvize Elite account (similar to portfolio) to receive real-time data instead of delayed data?

Thanks,

Nima

NimaMPH avatar Apr 17 '20 05:04 NimaMPH

I figured out how to obtain a cookie. But it does something weird to the scraper when you use it. My guess is because it's a different url. https://elite.finviz.com/screener.ashx rather than https://finviz.com/screener.ashx Here's my quick code to get the cookie header. That's as far as I got for now, I may come back later and work on this more.

def get_auth_header():
    login_url = 'https://finviz.com/login_submit.ashx'
    data = {
        'email': os.environ['FINVIZ_USERNAME'],
        'password': os.environ['FINVIZ_PASSWORD']
    }
    response = requests.post(url=login_url, data=data)
    for history in response.history:
        if history.cookies:
            for c in history.cookies:
                if c.name == '.ASPXAUTH':
                    return {
                        'Cookie': f'{c.name}={c.value}'
                    }

example response: print(get_auth_header())

{'Cookie': '.ASPXAUTH=1DC9E157078115DB9255E990EADE49A7C730035DEACF4F71559FF28438C6E10F92050B5AF0D3EA580F62565D75A8A9B788A099A3913C194C234710B1052C7DD74F942398AC78773BA8E82D1DC9E1570789031A9CC43D91A6C003C2A57C00D3DA7F40101EC2D1E9C56DDD8AB3F27E408A69BFA770789031A9025EDA596A4E38501A5CE079DA092104E392AF0D3EA580F62565D75A'}

NathanHRich avatar Apr 23 '20 04:04 NathanHRich

I figured out how to obtain a cookie. But it does something weird to the scraper when you use it. My guess is because it's a different url. https://elite.finviz.com/screener.ashx rather than https://finviz.com/screener.ashx Here's my quick code to get the cookie header. That's as far as I got for now, I may come back later and work on this more.

def get_auth_header():
    login_url = 'https://finviz.com/login_submit.ashx'
    data = {
        'email': os.environ['FINVIZ_USERNAME'],
        'password': os.environ['FINVIZ_PASSWORD']
    }
    response = requests.post(url=login_url, data=data)
    for history in response.history:
        if history.cookies:
            for c in history.cookies:
                if c.name == '.ASPXAUTH':
                    return {
                        'Cookie': f'{c.name}={c.value}'
                    }

example response: print(get_auth_header())

{'Cookie': '.ASPXAUTH=1DC9E157078115DB9255E990EADE49A7C730035DEACF4F71559FF28438C6E10F92050B5AF0D3EA580F62565D75A8A9B788A099A3913C194C234710B1052C7DD74F942398AC78773BA8E82D1DC9E1570789031A9CC43D91A6C003C2A57C00D3DA7F40101EC2D1E9C56DDD8AB3F27E408A69BFA770789031A9025EDA596A4E38501A5CE079DA092104E392AF0D3EA580F62565D75A'}

Hi! Any luck with this? Were you able to get it working?

williamp0044 avatar Dec 26 '20 09:12 williamp0044

This functionality would be very helpful. +1

DerekMelchin avatar Jun 19 '21 20:06 DerekMelchin

Hello, I managed to reuse @NathanHRich code in order to make it work on another finviz library called finvizfinance. It shouldn't be difficult porting the changes here. Is anyone still interested?

bestmazzo avatar Aug 09 '22 08:08 bestmazzo