Dec-13-2021, 02:22 PM
Greetings,
I have two questions in regards to the code below, I will make note of them inside the code itself.
Thank you
I have two questions in regards to the code below, I will make note of them inside the code itself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
session = requests.Session() # 1. I assign a session to the session variable but below, I re-assign a session.request to the session variable. Does this overwrite the initial session object? # should I define a new variable? #2. I need to send and receive cookies or cookie jar on each request. See below. def get_html(session, BASE_URL, PAGE): try : # How do I receive and send cookies with each request? I've researched it but the first time you enter a site, their aren't any cookies to be sent. PARAMS = { "startingIndex" : PAGE} session = session.get(BASE_URL, headers = HEADERS, params = PARAMS) # Is it considered good practice to re-assign this to the session variable? except requests.exceptions.RequestException as e: print ( "Failed to connect to host: " + BASE_URL) exit( "Check your internet connection. Then try to open the URL in a web browser. Program exiting." ) exit( "Could not establish connection to host. Terminating program!" ) return session |