selenium cookie get
时间: 2023-11-08 09:03:52 浏览: 78
CSDN获取selenium的cookie工具.spec
使用Selenium获取Cookie信息可以通过以下步骤实现:
1. 导入Selenium库:
```python
from selenium import webdriver
```
2. 创建WebDriver对象,并打开网页:
```python
driver = webdriver.Chrome() # 创建Chrome浏览器的WebDriver对象
driver.get('https://example.com') # 打开需要获取Cookie的网页
```
3. 获取Cookie信息:
```python
cookies = driver.get_cookies() # 获取当前页面的所有Cookie信息
for cookie in cookies:
print(cookie)
```
完整示例代码如下:
```python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://example.com')
cookies = driver.get_cookies()
for cookie in cookies:
print(cookie)
driver.quit()
```
阅读全文