2

I'm trying to get contest data from the url: "https://www.draftkings.com/contest/gamecenter/32947401"

If you go to this URL and aren't logged in, it'll just re-direct you to the lobby. If you're logged in, it'll actually show you the contest results.

Here's some things I tried:

-First, I used Chrome's Dev networking tools to watch requests while I manually logged in

-I then tried copying the cookie that I thought contained the authentication info, it was of the form:

 'ajs_anonymous_id=%123123123123123, mlc=true; optimizelyEndUserId'

-I then stored that cookie as an Evironment variable and ran this code:

HEADERS= {'cookie': os.environ['MY_COOKIE'] }
requests.get(draft_kings_url, headers= HEADERS)

No luck, this just gave me the lobby.

I then tried request's built in:

  • HTTPBasicAuth
  • HTTPDigestAuth

No luck here either.

I'm no python expert by far, and I've pretty much exhausted what I know and the search results I've found. Any ideas?

TrolliOlli
  • 827
  • 2
  • 8
  • 18

2 Answers2

0

The tool that you want is selenium. Something along the lines of:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get(r"https://www.draftkings.com/contest/gamecenter/32947401" )

username = browser.find_element_by_id("user")
username.send_keys("username")

password = browser.find_element_by_id("password")
password.send_keys("top_secret")

login = selenium.find_element_by_name("login")
login.click()
Batman
  • 8,137
  • 7
  • 38
  • 75
  • hey Batman. I used your answer with some modification and it seems to work! Once I'm logged in, is there any way to switch back to using requests? Or do I have to keep doing all work through the webdriver? – TrolliOlli Dec 01 '16 at 16:38
  • You absolutely can switch between the two. You just need to transfer the cookies from the webdriver to your requests session. Look at [this question](http://stackoverflow.com/questions/32639014/is-it-possible-to-transfer-a-session-between-selenium-webdriver-and-requests-s) – Batman Dec 01 '16 at 17:39
  • You can log in to draft kings with requests. Selenium is overkill. – pguardiario Dec 03 '16 at 09:46
0

Use fiddler to see the exact request they are making when you try to log in. Then use Session class in requests package.

import requests
session = requests.Session()
session.get('YOUR_URL_LOGIN_PAGE')

this will save all the cookies from your url in your session variable (Like when you use a browser). Then make a post request to the login url with appropriate data.

You dont have to manually pass cookie data as it is auto generated when you first visit a website. However you can set some header explicitly like UserAgent etc by:

session.headers.update({'header_name':'header_value'})

HTTPBasicAuth & HTTPDigestAuth might not work based on the website.

Manish Gupta
  • 4,210
  • 14
  • 51
  • 97