运行selenium后获取请求授权令牌

2024-04-19 16:40:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python和selenium创建一个应用程序,我想在登录到页面后从请求头获取授权令牌

from selenium import Chrome      
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait  
from selenium.webdriver.common.keys import Keys  
# For using sleep function because selenium  
# works only when the all the elemets of the  
# page is loaded. 
import time  

options = webdriver.ChromeOptions()

if not (showUI):
    options.add_argument('headless')
    options.add_argument('window-size=1920x1080')
    options.add_argument("disable-gpu")
options.add_argument("--log-level=3")
options.add_argument("'verify_ssl': False")
#Path to your chrome profile
options.add_argument("user-data-dir="+chromeProfilePath)
browser = Chrome()

url = 'https://example.com'
browser.get(url) 

user = browser.find_element_by_xpath('//*[@id="Username"]') 

# Enter User Name 
user.send_keys('USER') 

password = browser.find_element_by_xpath('//*[@id="Password"]') 

password.send_keys('PASSWORD')
password.send_keys(Keys.RETURN)

完成这部分代码后,我将登录该站点。现在我需要用于发送请求的授权令牌。如何获取请求标头


Tags: thefromimportbrowsersendaddbyselenium