前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python3实现自动登录网页版QQ

python3实现自动登录网页版QQ

作者头像
py3study
发布2020-01-03 10:59:55
3.6K0
发布2020-01-03 10:59:55
举报
文章被收录于专栏:python3python3python3

最近一直想搞一个自动登录的程序,今天琢磨了一会,也搞出来了。不过功能不多。但是对我来说,也是一个小小的进步吧。知识日积月累,自然就会的多了。废话不多说,代码最实际了。

环境:

  • 系统: windows10
  • IDE开发工具:Pycharm Professional
  • 模块: selenium,time

安装selinium:

pip install selenium


浏览器驱动配置:

Firefox驱动: GeckoDriver

1. 相关链接:
    GitHub:[github地址](https://github.com/mozilla/geckodriver)
   下载地址:[ffirefoxdriver下载](https://github.com/mozilla/geckodriver/releases)

根据自己平台和Firefox的版本来下载Firefox的驱动版本。不知道Firefox的版本和驱动版本是否对应,可以自行百度。

windows下, 解压geckodriver.zip, 将exe文件放到python的Scripts目录下。
linux下: 可以设置环境变量。

验证: 可以直接在cmd/linux终端敲geckodriver命令:
有geckodriver的正常输出说明OK。

Chrome驱动: chromedriver 官方网站:https://sites.google.com/a/chromium.org/chromedriver 下载地址:https://chromedriver.storage.googleapis.com/index.html

查看chrome浏览器的版本,再去下载与chrome浏览器对应的chrome驱动。

剩下的步骤与Firefox的步骤一致。不做详解。

pycharm破解网站: pycharm破解

代码如下:

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

def login():
    try:
        driver = webdriver.Firefox()

        url = "https://im.qq.com/index.shtml"
        driver.get(url)

        text = driver.find_element_by_id('topbar').text

        driver.find_element_by_id("login").click()
        time.sleep(5)

        # 打开QQ登录界面,准备登录
        driver.switch_to_frame('login_frame')
        driver.find_element_by_id("switcher_plogin").click()
        time.sleep(5)

        #填写QQ账号
        driver.find_element_by_id('u').send_keys('QQ号')
        time.sleep(5)

        #填写QQ密码:
        driver.find_element_by_id('p').send_keys('密码')

        #模拟点击登录按钮,执行登录
        driver.find_element_by_id('login_button').click()

        #退出浏览器,就退出QQ了,你可以根据需要自行设置睡眠时间。
        time.sleep(40)
        driver.quit()
    except:
        print("程序错误")
        print("请检查该脚本")

if __name__=='__main__':
    login()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 浏览器驱动配置:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档