Spaces:
Build error
Build error
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() | |