思路:
創(chuàng)建瀏覽器驅(qū)動(dòng)對(duì)象
加載登錄頁(yè)面
等待頁(yè)面加載完畢
切換到用戶名和密碼登錄模式
輸入手機(jī)號(hào), 注意此處需要等待并獲取輸入框
輸入密碼
點(diǎn)擊驗(yàn)證按鈕
獲取彈出驗(yàn)證圖片
使用超級(jí)鷹打碼平臺(tái)識(shí)別圖形的坐標(biāo)
獲取到坐標(biāo)信息, x,y坐標(biāo)分別除以2; 由于電腦分辨率太過(guò)了, 是原來(lái)的兩倍, 如果是普通分辨率可以除以2,直接用就可以了.
把鼠標(biāo)移動(dòng)到, 坐標(biāo)點(diǎn)的位置進(jìn)行點(diǎn)擊
點(diǎn)擊登錄按鈕
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver import ActionChains import time # 導(dǎo)入超級(jí)鷹 from chaojiying import chaojiying #根據(jù)系統(tǒng),可能截圖不成功,需要使用無(wú)頭瀏覽,mac系統(tǒng)可以不設(shè)置 options=webdriver.ChromeOptions() options.headless=True driver=webdriver.Chrome(options=potions) driver.get('http://www.zhaopingou.com/signin') driver.find_element_by_class_name('li02').click() wait=WebDriverWait(driver,20,0.5) # 賬號(hào)登錄 login_phone=wait.until(EC.visibility_of_element_located((By.ID,'pwd_login_phone'))) login_phone.send_keys('17724035140') # 密碼 driver.find_element_by_id('form_login_password').send_keys('961831740hzll') # 點(diǎn)擊獲取圖片 captcha = wait.until(EC.visibility_of_element_located((By.XPATH, '//div[@class="phone_login_pwd"]//iframe[starts-with(@id, "captcha_widget")]'))) captcha.click() # 點(diǎn)擊 # 保存圖片(可以不保存) captcha_element = wait.until(EC.visibility_of_element_located((By.XPATH, '//body[@class="graybc"]//iframe[starts-with(@id, "captcha_frame")]'))) captcha_element.screenshot('zhaopingou.png') # 將圖片轉(zhuǎn)換為二進(jìn)制 bytes_img=captcha_element.screenshot_as_png # print(bytes_img) result=chaojiying.post_pic(bytes_img,'9101') x,y=result['pic_str'].split(',') print(x,y) x=int(x) y=int(y) # ActionChains(driver).move_to_element_with_offset(bytes_img,x,y).click().perform() ActionChains(driver).move_to_element_with_offset(captcha_element, x, y).click().perform() time.sleep(2) driver.find_element_by_id('free_login_btn').click() print(driver.window_handles) driver.switch_to.window(driver.window_handles[0]) # time.sleep(5) driver.quit()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
