mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
19 lines
643 B
Markdown
19 lines
643 B
Markdown
用 selenium 登录网站,然后切换到 requests 读取网页。两者会共享登录信息。
|
||
|
||
```python
|
||
page = MixPage() # 创建页面对象,默认 driver 模式
|
||
page.get('https://gitee.com/profile') # 访问个人中心页面(未登录,重定向到登录页面)
|
||
|
||
page.ele('@id:user_login').input('your_user_name') # 使用 selenium 输入账号密码登录
|
||
page.ele('@id:user_password').input('your_password\n')
|
||
sleep(1)
|
||
|
||
page.change_mode() # 切换到 session 模式
|
||
print('登录后title:', page.title, '\n') # 登录后 session 模式的输出
|
||
```
|
||
|
||
输出:
|
||
|
||
```
|
||
登录后title: 个人资料 - 码云 Gitee.com
|
||
``` |