2

I want to login to stockcharts.com webpage and then play with something available to its users after logged in.

Here is what I tried:

from requests import session

payload = { 'form_Name':         'Login',
            'zendesk_timestamp': '',
            'redirect':          '',
            'form_UserID':       'XXXX@YYY.com',
            'form_UserPassword': 'ZZZZ',
            'form_RememberMe':   ''
            }

c        = session()
this_url = 'https://stockcharts.com/scripts/php/dblogin.php'

c.post( this_url, data = payload )

request = c.get( 'http://stockcharts.com/h-hd/?GOOG' )

I then play with the fetched historical data.

I used spyder, and below are the error messages I got:

raise ConnectionError(e)

requests.exceptions.ConnectionError: HTTPSConnectionPool(
         host = 'stockcharts.com', port = 443 ):
         Max retries exceeded with url: /scripts/php/dblogin.php
         ( Caused by <class 'socket.error'>:
                  [Errno 104] Connection reset by peer )

I have been googling for its answer for a while, tried a few things like ( the code and title are actually "borrowed" from them )

How to use Python to login to a webpage and retrieve cookies for later usage?

Python login to webpage and get contents of session protected page

I just cannot make it work for me. I use Python for some time but I think I am still somehow new to such kind of programming.

could anyone help me out? appreciate your help a lot!!

JW

Community
  • 1
  • 1
jgroup_jw
  • 31
  • 4
  • Can you confirm, that your login-credentials are both correct and valid, once tried manually, to get logged into your stockcharts.com account? – user3666197 Oct 12 '14 at 16:36
  • thank you again @user3666197 for making it much more readable. It looks much better now. – jgroup_jw Oct 12 '14 at 16:37
  • @user3666197. Yes I tried. that was the very first thing I checked when I saw the error. – jgroup_jw Oct 12 '14 at 16:38
  • You may try your code-concept "against" free-charts, if you opt to. Your Proof-of-Concept prototype may be run with `http://stockcharts.com/freecharts/perf.php?[MM]` and many others. – user3666197 Oct 12 '14 at 16:39
  • @user3666197 Yes we do also use other information from stockcharts.com.It is a good website. the information I try to get from [link] (http://stockcharts.com/h-hd/?GOOG) is the historical adjusted stock price/volume information, which is only available for registered users. therefore I must login first and then get the historical adjusted information. – jgroup_jw Oct 12 '14 at 16:49

1 Answers1

0

Issue is not in Python, but rather the <form <input ...> syntax

You may want to drill-down into the current stockcharts.com login-interface.

dblogin.php expects ( as of 2014-10-12 ) to receive this set of parameters:

  1. form_Name == "Login"
  2. zendesk_timestamp
  3. redirect
  4. form_UserID == <<_aText_>>
  5. form_UserPassword == <<_aText_>>
  6. form_RememberMe

So you need to meet the php-interface expectations to get this step farther.

You shall inspect your real-(manual)-login values upon being submitted, blank/empty strings do not work as substitutes.

user3666197
  • 1
  • 6
  • 50
  • 92
  • I tried, but it still does not work, see updated post. thank you again @user3666197. – jgroup_jw Oct 12 '14 at 17:30
  • What value do you provide in timestamp? – user3666197 Oct 12 '14 at 17:59
  • an empty string ''. In payload, I used the exact same values except "form_UserID" and "form_UserPassword" as in the original post. – jgroup_jw Oct 12 '14 at 18:25
  • The types of some fields (like zendesk_timestamp) are "hidden". As @user3666197 pointed out, there might be some specific values for those fields. does anyone know how to to get values for those "hidden" fields? thanks – jgroup_jw Oct 12 '14 at 21:41
  • As written above: You shall inspect your real-(manual)-login values upon being submitted, blank/empty strings do not work as substitutes. – user3666197 Oct 12 '14 at 21:53
  • how can I get those values? I input user ID & password, and then click "login". is there a way that I can somehow "see" the strings that webpage sends to its server after I click "login"? – jgroup_jw Oct 12 '14 at 22:15
  • Yes, you may use packet-level sniff or you may relay+route your reverse-engineering code to direct http-protocol-session through an http-urllib decoder/transponder-proxy, to see the [onSubmit POST values] – user3666197 Oct 13 '14 at 19:00