selenium+python+chromedriver.exe爬取登录QQ邮箱

这是笔者面试的一道题,回到家中自己去撸代码。

#导入所需要的包
from selenium import webdriver
from selenium.webdriver.common import action_chains
import time
#读取工具路径
driver=webdriver.Chrome('F:\du\chromedriver_win32\chromedriver.exe')
#爬取的网址
driver.get('https://ui.ptlogin2.qq.com/cgi-bin/login?style=9&appid=522005705&daid=4&s_url=https%3A%2F%2Fw.mail.qq.com%2Fcgi-bin%2Flogin%3Fvt%3Dpassport%26vm%3Dwsk%26delegate_url%3D%26f%3Dxhtml%26target%3D&hln_css=http%3A%2F%2Fmail.qq.com%2Fzh_CN%2Fhtmledition%2Fimages%2Flogo%2Fqqmail%2Fqqmail_logo_default_200h.png&low_login=1&hln_autologin=%E8%AE%B0%E4%BD%8F%E7%99%BB%E5%BD%95%E7%8A%B6%E6%80%81&pt_no_onekey=1')
#进行解析和输入账号密码
zh=driver.find_element_by_xpath('//input[@class="inputstyle"]').send_keys("账号")
mm=driver.find_element_by_xpath('//*[@id="p"]').send_keys("密码")
login=driver.find_element_by_xpath('//*[@id="go"]')

action=action_chains.ActionChains(driver)
#设置左键点击
#action.click(login)
action.click(zh).click(mm).click(login).perform()
time.sleep(2)
#关闭并退出
driver.close()
driver.quit()

你可能感兴趣的:(selenium+python+chromedriver.exe爬取登录QQ邮箱)