国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python使用selenium實(shí)現(xiàn)網(wǎng)頁用戶名 密碼 驗(yàn)證碼自動(dòng)登錄功能

2020-01-04 15:04:11
字體:
供稿:網(wǎng)友

好久沒有學(xué)python了,反正各種理由吧(懶惰總會(huì)有千千萬萬的理由),最近網(wǎng)上學(xué)習(xí)了一下selenium,實(shí)現(xiàn)了一個(gè)簡單的自動(dòng)登錄網(wǎng)頁,具體如下。

1.安裝selenium:

如果你已經(jīng)安裝好anaconda3,直接在windows的dos窗口輸入命令安裝selenium:

python -m pip install --upgrade pip

查看版本pip show selenium

2.接著去http://chromedriver.storage.googleapis.com/index.html下載chromedriver.exe(根據(jù)chrome的版本下載對(duì)應(yīng)的)

3.將下載好的chromedriver.exe解壓后放到指定目錄

4.安裝tesseract-ocr.exe 配置環(huán)境變量

5.安裝pytesseract : pip install pytesseract

6.python腳本

思路:6.1登錄頁面按F12檢查元素,獲取用戶名 密碼 驗(yàn)證碼 驗(yàn)證碼圖片的元素id

   6.2.調(diào)用chromedriver

   6.3.截取驗(yàn)證碼圖片的位置

   6.4.pytesseract識(shí)別圖片中字符,最后驗(yàn)證碼識(shí)別為空!!???這個(gè)待解決

   6.5.腳本如下:

from selenium import webdriverfrom PIL import Imageimport pytesseractimport os,timechromedriver = "D:/Program Files/Anaconda3/selenium/webdriver/chromedriver.exe" #這里寫本地的chromedriver 的所在路徑os.environ["webdriver.Chrome.driver"] = chromedriver #調(diào)用chrome瀏覽器driver = webdriver.Chrome(chromedriver)driver.get("http://xxxx.com") #該處為具體網(wǎng)址driver.refresh() #刷新頁面driver.maximize_window() #瀏覽器最大化#獲取全屏圖片,并截取驗(yàn)證碼圖片的位置driver.get_screenshot_as_file('a.png')location = driver.find_element_by_id('imgValidateCode').locationsize = driver.find_element_by_id('imgValidateCode').sizeleft = location['x']top = location['y']right = location['x'] + size['width']bottom = location['y'] + size['height']a = Image.open("a.png")im = a.crop((left,top,right,bottom))im.save('a.png')time.sleep(1)#打開保存的驗(yàn)證碼圖片image = Image.open("a.png")#圖片轉(zhuǎn)換成字符vcode = pytesseract.image_to_string(image)print(vcode)#填充用戶名 密碼 驗(yàn)證碼driver.find_element_by_id("staffCode").send_keys("username")driver.find_element_by_id("pwd").send_keys("password")driver.find_element_by_id("validateCode").send_keys(vcode)#點(diǎn)擊登錄 driver.find_element_by_id("loginBtn").click()

總結(jié)

以上所述是小編給大家介紹的Python實(shí)現(xiàn)網(wǎng)頁用戶名 密碼 驗(yàn)證碼自動(dòng)登錄功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到python教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 全南县| 长垣县| 新蔡县| 武邑县| 区。| 桑日县| 永胜县| 康乐县| 平谷区| 泗洪县| 邹城市| 武宣县| 林州市| 安溪县| 东乡| 卢氏县| 固安县| 顺昌县| 河南省| 天津市| 鹰潭市| 嘉禾县| 睢宁县| 赫章县| 宽甸| 额济纳旗| 和林格尔县| 泰来县| 安新县| 鹤岗市| 孟村| 蓝山县| 苏尼特左旗| 岱山县| 乌鲁木齐市| 同仁县| 漳浦县| 安达市| 乐清市| 峨边| 连南|