DrissionPage/docs/特性演示/模式切换.md
2021-12-10 19:02:42 +08:00

19 lines
643 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

用 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
```