3

上班时间在CSDN摸鱼被女领导发现了—她问我怎么用python自动登录CSDN【2021.04.20】

 3 years ago
source link: https://blog.csdn.net/weixin_42350212/article/details/115898831
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

上班时间在CSDN摸鱼被女领导发现了—她问我怎么用python自动登录CSDN【2021.04.20】

目录

页面分析

引入selenium模块及驱动

1、并将安装好的Chromedriver.exe引入到代码中

2、浏览器驱动引入

爬虫模拟登录

1、设置网址链接

2、切换到账号密码登录

3、找到用户名密码的控件ID

4、注入用户名和密码

5、模拟登录点击

成功登录CSDN


CSDN登录页面如下图

引入selenium模块及驱动

1、并将安装好的Chromedriver.exe引入到代码中

2、浏览器驱动引入

驱动下载地址:

https://download.csdn.net/download/weixin_42350212/14983610

将驱动下载后,复制chromedriver.exe 到谷歌浏览器的安装路径下,与Chrome.exe启动文件并列的目录下:

爬虫模拟登录

1、设置网址链接

2、切换到账号密码登录

使用selenium模拟点击 账号密码登录的选项

3、找到用户名密码的控件ID

4、注入用户名和密码

根据页面代码分析,获得用户名的id属性为all,密码的id属性为password-number

使用python代码,注入用户名密码

5、模拟登录点击

分析页面结构,模拟点击登录按钮。

分析可获得,登录按钮的class属性为btn btn-primary,根据class来锁定该按钮

成功登录CSDN

欢迎关注公众号:hacklex  提供各种资源下载。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK