1 #实现163网站的注册 2 from selenium import webdriver 3 import time 4 driver = webdriver.Chrome() 5 url = 'https://mail.163.com/' 6 driver.get(url) 7 # 定位注册新账号 8 el= driver.find_element_by_xpath('//*[@id="commonOperation"]/a[2]').click() 9 time.sleep(5) 10 #切换句柄到注册页面 11 hand_list = driver.window_handles 12 driver.switch_to.window(hand_list[1]) 13 driver.find_element_by_xpath('//*[@id="username"]').send_keys('[email protected]') 14 driver.find_element_by_xpath('//*[@id="password"]').send_keys('cd123456') 15 driver.find_element_by_xpath('//*[@id="phone"]').send_keys('17762443345') 16 driver.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/div[4]/span').click() 17 driver.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/div[5]/a[1]').click() 18 #163网站登录 19 from selenium import webdriver 20 import time 21 driver =webdriver.Chrome() 22 main_url="https://mail.163.com/" 23 driver.get(main_url) 24 time.sleep(3) 25 #点击切换到帐号密码登录 26 driver.find_element_by_id("switchAccountLogin").click() 27 #找到iframe 28 login_iframe=driver.find_element_by_xpath('//iframe[starts-with(@id, "x-URS-iframe")]') 29 driver.switch_to.frame(login_iframe) 30 username=driver.find_element_by_xpath('//input[@name="email"]') 31 password=driver.find_element_by_xpath('//input[@name="password"]') 32 username.send_keys("[email protected]") 33 password.send_keys("cd123456") 34 driver.find_element_by_xpath('//a[@id="dologin"]').click() 35 driver.find_element_by_xpath('//*[@id="_mail_component_53_53"]').click()
虽然自己不太熟悉,其中也会报错,每次红我就在想自己是不是真的不适合学代码。
好的程序员都是要一直敲敲敲还是要多练多练多练