需要selenium包和chorme相应的插件
模拟登陆百度账号(只是输入账号密码点击登陆)
from selenium import webdriver
from time import sleep
#-*- coding:utf8 -*-
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://baidu.com')
sleep(2)
driver.find_element_by_xpath('//*[@id="u1"]/a[7]').click()
sleep(2)
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_10__footerULoginBtn"]').click()
driver.find_element_by_id('TANGRAM__PSP_10__userName').clear()
driver.find_element_by_id('TANGRAM__PSP_10__userName').send_keys('123')
driver.find_element_by_id('TANGRAM__PSP_10__password').clear()
driver.find_element_by_id('TANGRAM__PSP_10__password').send_keys('222')
模拟登陆QQ空间,主要步骤要先定位frame
from selenium import webdriver
from time import sleep
# -*- coding:utf8 -*-
from selenium import webdriver
QQ_number = input("QQ:")
password = input("password:")
driver = webdriver.Chrome()
driver.get("http://qzone.qq.com")
driver.switch_to_frame('login_frame')
sleep(2)
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()
driver.find_element_by_id('u').send_keys(QQ_number)
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys(password)#password
driver.find_element_by_id('login_button').click()
driver.quit()