简体   繁体   English

如何在python中的GET和POST请求后打开浏览器选项卡

[英]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.我不确定这是否可行,但基本上,我试图在 Chrome 中打开一个选项卡来显示我的 GET 和 POST 请求的结果。 For instance, lets say im using Python requests to POST log in data to a site.例如,假设我使用 Python 请求将登录数据 POST 到站点。 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.然后我想在 POST 请求之后打开一个 chrome 选项卡,看看我是否做对了,并从 Chrome 本身的那个网页上继续。 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?我知道我可以使用 response.text 来检查我的 POST 请求是否成功,但是有没有办法我可以物理打开一个 chrome 选项卡来查看结果本身? Im guessing there would be a need to export some sort of cookies as well?我猜还需要导出某种 cookie 吗? Any help or insights would be appreciated.任何帮助或见解将不胜感激。

When using selenium, you need to remove headless option for browser:使用 selenium 时,您需要删除浏览器的 headless 选项:

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.之后浏览器将保持打开状态,您将能够继续手动工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM