lilexperimenter
lilexperimenter

Reputation: 23

How to open a browser tab after GET and POST requests in python

Im not sure if this is possible, but basically, I'm trying to open a tab in Chrome to show the outcome of my GET and POST requests. For instance, lets say im using Python requests to POST log in data to a site. I would want to then open a chrome tab after that POST request to see if I did it correctly, and also to continue on that webpage from there in Chrome itself. I know I can use response.text to check if my POST request succeeded, but is there a way I can physically open a chrome tab to see the result itself? Im guessing there would be a need to export some sort of cookies as well? Any help or insights would be appreciated.

Upvotes: 1

Views: 375

Answers (1)

Alexandra Dudkina
Alexandra Dudkina

Reputation: 4462

When using selenium, you need to remove headless option for browser:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
#chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('<PATH_TO_CHROMEDRIVER>', options=chrome_options)

# load page via selenium
wd.get("<YOUR_TARGET_URL>")

# don't close browser
# wd.quit()

Also remove closing browser in the end of code.

After that browser will remain open and you will be able to continue work manually.

Upvotes: 1

Related Questions