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

首頁 > 編程 > Python > 正文

Python使用selenium實現網頁用戶名 密碼 驗證碼自動登錄功能

2020-02-23 00:09:13
字體:
來源:轉載
供稿:網友

好久沒有學python了,反正各種理由吧(懶惰總會有千千萬萬的理由),最近網上學習了一下selenium,實現了一個簡單的自動登錄網頁,具體如下。

1.安裝selenium:

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

python -m pip install --upgrade pip

查看版本pip show selenium

2.接著去http://chromedriver.storage.googleapis.com/index.html下載chromedriver.exe(根據chrome的版本下載對應的)

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

4.安裝tesseract-ocr.exe 配置環境變量

5.安裝pytesseract : pip install pytesseract

6.python腳本

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

   6.2.調用chromedriver

   6.3.截取驗證碼圖片的位置

   6.4.pytesseract識別圖片中字符,最后驗證碼識別為空!!???這個待解決

   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 #調用chrome瀏覽器driver = webdriver.Chrome(chromedriver)driver.get("http://xxxx.com") #該處為具體網址driver.refresh() #刷新頁面driver.maximize_window() #瀏覽器最大化#獲取全屏圖片,并截取驗證碼圖片的位置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)#打開保存的驗證碼圖片image = Image.open("a.png")#圖片轉換成字符vcode = pytesseract.image_to_string(image)print(vcode)#填充用戶名 密碼 驗證碼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)#點擊登錄 driver.find_element_by_id("loginBtn").click()

總結

以上所述是小編給大家介紹的Python實現網頁用戶名 密碼 驗證碼自動登錄功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 深圳市| 雷州市| 神农架林区| 和平县| 广南县| 临沧市| 城固县| 镇平县| 郯城县| 桑日县| 肃宁县| 马尔康县| 武穴市| 虞城县| 阳东县| 彭阳县| 南京市| 海林市| 建平县| 高阳县| 克拉玛依市| 调兵山市| 沙雅县| 登封市| 青海省| 宁蒗| 福州市| 新乐市| 财经| 公主岭市| 青铜峡市| 游戏| 杭锦后旗| 孟津县| 云和县| 五大连池市| 铜鼓县| 喀什市| 安多县| 沙田区| 永善县|