1.打开网页输入账号密码登录# `6 B' V! E j7 F, S" _% l
===========================================================
- _1 K2 j( Q' S: L3 ?& v' @#引入selenium库中的webdriver模块" G# J+ d( z; [: N1 }0 a! w6 C2 }
from selenium import webdriver1 ]+ [" w: T8 d) d& \2 w
#引入time库
^; s7 h$ }) T, |import time. Y( H: ]4 M" Z9 t% T
#打开google浏览器* h9 k2 O$ n/ g/ A: l
driver = webdriver.Chrome()
! e" O7 S0 W7 W3 {#打开126邮箱平台
. D: U" s+ p4 hdriver.get('www.52ocean.cn')
; R8 s5 S4 m# d" `/ ?'''
: K L$ ]( l: F4 ^考虑到网页打开速度取决于每个人的电脑和网速, E5 I' T3 M& `. ?8 o
使用time库sleep()方法,让程序睡眠5秒
" x7 c8 a; y% S/ S'''
+ a7 H& l$ l+ { I3 I: G. b; Stime.sleep(5)
: a! w5 `8 y' {( v% |9 B#在主页面点击登录按钮,进入登录页面
+ j- S2 F( e gdriver.find_element_by_xpath('//*[@id="notlogin"]/span/a[1]').click()" Y3 \, e( R4 a) e
#输入账号和密码1 c2 ~; z0 D' H) F; Y
driver.find_element_by_xpath('//*[@id="lUsername"]').send_keys('账号')5 l. \$ L, ^3 `5 v: D) L4 w' Y3 [
driver.find_element_by_xpath('//*[@id="lPassword"]').send_keys('密码')- z3 i& C" ^ W
#点击登录按钮5 n" d6 k* Q& }' U& e, a
driver.find_element_by_xpath('//*[@id="f_sign_up"]').click()
! o0 K9 Y- T9 P6 c============================================================( r" [2 e3 q" f0 ~( H% ~& |
2 C; g9 O3 z% e0 K3 [
' k( I z: t) I- V0 d/ n
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |