Spaces:
Build error
Build error
File size: 578 Bytes
e37298f |
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 |
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# 设置无头浏览器选项
options = Options()
options.headless = True
# 初始化WebDriver
driver = webdriver.Chrome(options=options)
# 访问网址
driver.get("https://example.com/")
# 网页加载后,Selenium会处理JavaScript代码,包括设置cookie和跳转
# 您可以检查cookie
cookies = driver.get_cookies()
print(cookies)
# 您也可以获取当前URL,检查是否发生了跳转
current_url = driver.current_url
print(current_url)
# 关闭浏览器
driver.quit()
|