python使用chrom登陆微博

# -*- coding:utf-8 -*-

import json
import requests
from selenium import webdriver
import time

class WeiboAuthorize(object):
loginUrl = 'https://passport.weibo.cn/signin/login'
chromePath = './chromedriver.exe'

def __init__(self):
pass

def getweibouser(self):
return {'username': '你的微博用户名','password': '你的微博密码'}
    def loginWeibo(self, username, password):
self.driver = webdriver.Chrome(self.chromePath)

self.driver.get(self.loginUrl)
time.sleep(1)

self.driver.find_element_by_id("loginName").send_keys(username)
self.driver.find_element_by_id("loginPassword").send_keys(password)

time.sleep(1)
self.driver.find_element_by_id("loginAction").click()
time.sleep(3)
self.driver.get(self.authorizeUrl)
time.sleep(3)
self.driver.close()

if __name__ == '__main__':
c = WeiboAuthorize()
params = c.getweibouser()
if params['username'] and params['password'] :
c.loginWeibo(params['username'], params['password'])

posted @ 2019-07-24 17:48  爱冯果  阅读(342)  评论(0编辑  收藏  举报