General Problem
I am trying to gather stock data from Investors Business Daily (IBD) using Python. My goal is to take a stock list and get data for each ticker in the list. The specific page I am interested in is what IBD calls the stock checkup. This page is only viewable for paid subscribers (I am using a free trial).
Specifics
I am trying to use the requests library to login to the session and then use .get to access the stock checkup page. Python version 3.7
import requests
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "DNT": "1", "Connection": "close", "Upgrade-Insecure-Requests": "1"}
LOGIN = 'https://myibd.investors.com/secure/signin.aspx?login'
PROTECTED_PAGE = 'https://research.investors.com/stock-checkup/nasdaq-applied-materials-inc-amat.aspx'
payload = {
'username': 'blahblah@gmail.com'
,'password': 'secretpw'
}
with requests.session() as s:
s.post(LOGIN, data=payload, headers = headers)
response = s.get(PROTECTED_PAGE, headers = headers)
print(response.text)
From other posts I've learned to look for the login form in the html to find the specific tag names for the username, password and other inputs. This is how I found the information for the payload above. I believe there are also hidden inputs that are making this more difficult than I hoped for (eg. __VIEWSTATE). The response text that I receive back indicates that I have not logged in and there is not specific information on the stock of interest (AMAT).
Is there a better way to do this? I have also tried using Selenium but there were issues with that as well. Is the IBD website really that tricky to login to or am I missing something? I've spent countless hours on this so any help is much appreciated!