Python selenium实现微博自动登录的示例代码
2018-05-16 09:30
1346 查看
(一)编程环境
- 操作系统:Win 10
- 编程语言:Python 3.6
(二)安装selenium
这里使用selenium实现。
如果没有安装过python的selenium库,则安装命令如下
pip install selenium
(三)下载ChromeDriver
因为selenium要用到浏览器的驱动,这里我用的是Google Chrome浏览器,所以要先下载ChromeDriver.exe并放到C:\Program Files (x86)\Google\Chrome\Application\目录下
(四)分析微博登录界面
通常而言,m站的网页结构比pc站要简单的多,咱们可以从m站入手。微博m站登录界面的网址是 https://passport.weibo.cn/signin/login
在Chrome浏览器中打开此地址,并右键点击界面的任何位置-->查看网页源代码,发现邮箱/手机号框的id为loginName,密码输入框的id为loginPassword,登录按纽的id为loginAction。
(五)编写python程序
from selenium import webdriver import time browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe") browser.get('https://passport.weibo.cn/signin/login') time.sleep(5) browser.find_element_by_id("loginName").send_keys("your login name") browser.find_element_by_id("loginPassword").send_keys("your password") time.sleep(5) browser.find_element_by_id("loginAction").click()
执行后可以看到自动登录的过程及登录成功的界面
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- Python Selenium Cookie 绕过验证码实现登录示例代码
- python+selenium实现登录账户后自动点击的示例
- Python实现登录接口的示例代码
- Python实现自动添加脚本头信息的示例代码
- python实现校园网自动登录的示例讲解
- Python实现Selenium实现自动登录CSDN
- Python+Selenium实现新浪微博自动登录
- Python爬虫 Selenium实现自动登录163邮箱和Locating Elements介绍
- 使用python实现baidu hi自动登录的代码
- python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
- selenium+python实现自动登录脚本
- Python使用selenium实现网页用户名 密码 验证码自动登录功能
- Python代码登录新浪微博并自动发微博
- Python实现自动添加脚本头信息的示例代码
- [Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍
- Python Selenium实现自动登录163邮箱
- python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
- selenium2+python_用cookie实现自动登录(百度首页为例)
- python itchat实现微信自动回复的示例代码