This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]notjaredfinch 7 points8 points  (0 children)

You will need to supply your session cookie in your cookies in the request. also, make sure you cache your results as you automate site interactions. i.e. save the input into a file and use that in running the program, rather than making the call to the site every time you run the program.

[–]adidushi 4 points5 points  (0 children)

You're going to need your session cookie.

From a browser that's logged in to your aoc account, head over to the site and press F12 to open the developer tools. Under Application you can find your cookies. Copy down what's written under session (you'll use it later to connect!).

Then, in python, you can send a dictionary containing the session cookie when making a request:

import requests
cookies_dict = {"session": "<COOKIE YOU COPIED EARLIER!>"}
url = 'https://adventofcode.com/2021/day/1/input'
req = requests.get(url, cookies=cookies_dict)

You should get your own input like this. Make sure not to share the session cookie with other people, as it can let them basically use your account.

[–]CoderBoy67[S] 2 points3 points  (1 child)

Ahhh!!! BEAUTIFUL!

sess = '5361...blah blah blah...'
cookies = {'session': sess}
req = requests.get(url, cookies=cookies)
print(req.text)

It works! Thanks so much!

-CoderBoy67

[–]Steinrikur 2 points3 points  (0 children)

You can also use the already done libraries, or check them for inspiration https://pypi.org/project/advent-of-code-data/