婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > python爬蟲之利用selenium模塊自動登錄CSDN

python爬蟲之利用selenium模塊自動登錄CSDN

熱門標簽:南京銷售外呼系統軟件 地圖標注的意義點 蓋州市地圖標注 地圖標注微信發送位置不顯示 浙江電銷卡外呼系統好用嗎 上海機器人外呼系統哪家好 315電話機器人廣告 地圖制圖標注位置改變是移位嗎 房產電銷外呼系統

一、頁面分析

CSDN登錄頁面如下圖

二、引入selenium模塊及驅動

2.1 并將安裝好的Chromedriver.exe引入到代碼中

# -*- coding:utf-8 -*-
from selenium import webdriver  
import os
import time
#引入chromedriver.exe
chromedriver="C:/Users/lex/AppData/Local/Google/Chrome/Application/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chromedriver)

2.2 瀏覽器驅動引入

將驅動下載后,復制chromedriver.exe 到谷歌瀏覽器的安裝路徑下,與Chrome.exe啟動文件并列的目錄下:

三、爬蟲模擬登錄

3.1 設置網址鏈接

#設置瀏覽器需要打開的url
url = "https://passport.csdn.net/login?code=public"  
browser.get(url)

3.2 切換到賬號密碼登錄

使用selenium模擬點擊 賬號密碼登錄的選項

#使用selenium選擇 賬號登錄按鈕
browser.find_element_by_link_text("賬號密碼登錄").click()

3.3 找到用戶名密碼的控件ID

3.4 注入用戶名和密碼

根據頁面代碼分析,獲得用戶名的id屬性為all,密碼的id屬性為password-number

使用python代碼,注入用戶名密碼

browser.find_element_by_id("all").clear()
browser.find_element_by_id("all").send_keys("xxxx@gmail.com")
time.sleep(2)
browser.find_element_by_id("password-number").clear()
browser.find_element_by_id("password-number").send_keys("1212121212")

3.5 模擬登錄點擊

分析頁面結構,模擬點擊登錄按鈕。

分析可獲得,登錄按鈕的class屬性為btn btn-primary,根據class來鎖定該按鈕

time.sleep(1)
#增加一秒鐘的時間間隔
browser.find_element_by_css_selector("[class='btn btn-primary']").click()

四、成功登錄CSDN

五、完整代碼

# -*- coding:utf-8 -*-
import os
import time
from selenium import webdriver # 從selenium導入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.chrome.options import Options
import json
import time
#引入chromedriver.exe
chromedriver="C:/Users/lex/AppData/Local/Google/Chrome/Application/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chromedriver)
#設置瀏覽器需要打開的url
url = "https://passport.csdn.net/login?code=public"  
browser.get(url)
browser.find_element_by_link_text("賬號密碼登錄").click()
browser.find_element_by_id("all").clear()
browser.find_element_by_id("all").send_keys("你的郵箱地址")
time.sleep(1)
browser.find_element_by_id("password-number").clear()
browser.find_element_by_id("password-number").send_keys("你的登錄密碼")
time.sleep(1)
browser.find_element_by_css_selector("[class='btn btn-primary']").click()

到此這篇關于python爬蟲之利用selenium模塊自動登錄CSDN的文章就介紹到這了,更多相關python自動登錄CSDN內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python爬蟲請求庫httpx和parsel解析庫的使用測評
  • Python爬蟲之爬取最新更新的小說網站
  • 用Python爬蟲破解滑動驗證碼的案例解析
  • Python爬蟲爬取愛奇藝電影片庫首頁的實例代碼
  • Python爬蟲之爬取嗶哩嗶哩熱門視頻排行榜
  • 上手簡單,功能強大的Python爬蟲框架——feapder
  • python爬蟲之bs4數據解析
  • python爬蟲之爬取百度翻譯
  • python爬蟲基礎之簡易網頁搜集器
  • python爬蟲之爬取筆趣閣小說
  • python爬蟲之利用Selenium+Requests爬取拉勾網
  • python基礎之爬蟲入門

標簽:日照 貴州 雙鴨山 克拉瑪依 赤峰 陽泉 臨汾 金華

巨人網絡通訊聲明:本文標題《python爬蟲之利用selenium模塊自動登錄CSDN》,本文關鍵詞  python,爬蟲,之,利用,selenium,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python爬蟲之利用selenium模塊自動登錄CSDN》相關的同類信息!
  • 本頁收集關于python爬蟲之利用selenium模塊自動登錄CSDN的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 克东县| 临江市| 泰安市| 江城| 汉源县| 车险| 雷州市| 桐庐县| 河东区| 临安市| 望城县| 南平市| 灌南县| 澄城县| 寻乌县| 双柏县| 泾川县| 仁化县| 察雅县| 兴义市| 西乌珠穆沁旗| 射阳县| 连平县| 朝阳市| 外汇| 钦州市| 泸西县| 玉田县| 青河县| 阳高县| 繁昌县| 班玛县| 久治县| 临安市| 奈曼旗| 阿拉善盟| 武安市| 拉萨市| 永春县| 和静县| 合肥市|