1. 程式人生 > >python實現自動化登陸不需要密碼

python實現自動化登陸不需要密碼

比如我下面這段給出的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