您的位置:首页 > 编程语言 > Python开发

python实现自动化登陆不需要密码

2016-06-08 11:00 537 查看
比如我下面这段给出的example,可以完成你的需求,模拟登录人人

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

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

wd = webdriver.Firefox()
wd.get("http://www.renren.com")
wd.maximize_window()

try:
"""这段可以查看selenium的源码,属于smart wait"""
email = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'email')),message=u'元素加载超时!')
email.send_keys("*** 你的账号 ***")
passwd = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'password')),message=u'元素加载超时!')
passwd.send_keys("*** 你的密码 ***")
wd.find_element_by_id("login").click() #点击登录
except NoSuchElementException as e:
print e.message
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息