這是第一次代碼,結果為失敗
-
匯入要使用的資料包
from typing import re from selenium import webdriver import time
-
呼叫瀏覽器driver自動打開一個視窗(這里使用的是谷歌瀏覽器版本)
wb = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe") wb.implicitly_wait(3) -
微博登入入口有兩個,可以隨意使用(入口不同,用戶名密碼的路徑就有所不同,點擊F12進入開發模式自行尋找)
wb.get('https://weibo.com/')or
wb.get('https://passport.weibo.cn/signin/login') -
輸入你的用戶名:鎖定用戶名輸入框-輸入
elem = wb.find_element_by_xpath("//*[@id='loginName']") elem.send_keys("********") # 輸入你的用戶名 -
輸入密碼:鎖定密碼輸入框-輸入
elem = wb.find_element_by_xpath("//*[@id='loginPassword']") elem.send_keys("*********") # 輸入密碼 elem = wb.find_element_by_xpath("//*[@id='loginAction']") elem.click() -
簡化代碼輸入版
wb.find_element_by_xpath("//*[@id='loginName']").send_keys("********") # 輸入你的用戶名 wb.find_element_by_xpath("//*[@id='loginPassword']").send_keys("*********") # 輸入密碼 -
點擊登錄(回車)
wb.find_element_by_xpath("//*[@id='loginAction']").click()因為新浪微博的等入使用了手機驗證,所以自動登錄就卡住了,so,這是一次失敗的自動代碼,
-
各個瀏覽器的driver版本下載鏈接
http://npm.taobao.org/mirrors/chromedriver/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/264069.html
標籤:Python
上一篇:Python亂碼問題九問
