Selenium滑块验证登录天猫淘宝网站
生活随笔
收集整理的這篇文章主要介紹了
Selenium滑块验证登录天猫淘宝网站
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
模擬登錄天貓和淘寶網址,直接跳過滑塊驗證的方法。
import timefrom selenium.webdriver import Chrome from selenium.webdriver import ChromeOptionsoption = ChromeOptions() # 此步驟很重要,設置為開發者模式,防止被各大網站識別出來使用了Selenium option.add_experimental_option('excludeSwitches', ['enable-automation']) option.add_argument("--disable-blink-features") option.add_argument("--disable-blink-features=AutomationControlled") driver = Chrome(options=option) url = "https://www.tmall.com/?spm=a1z10.1-b-s.0.0.3d962cbdmcnf3c"driver.get(url) # 查找搜索框,天貓會不定期更改元素,注意自行更改 send = driver.find_element_by_xpath("//input[@class='rax-textinput rax-textinput-placeholder-0 SearchInput--searchInputContent--1USWNEl']") send.click() time.sleep(2) send.send_keys("良品鋪子") # 點擊搜索按鈕進行搜索 search = driver.find_element_by_xpath("//div[@class='rax-view-v2 SearchInput--searchButton--1Sz2UIn']") time.sleep(1) search.click() time.sleep(3) # 轉到新窗口 windows = driver.window_handles driver.switch_to.window(windows[-1]) # 查詢用戶登錄名輸入框 login_name = driver.find_element_by_id("fm-login-id") # 手機號或用戶名 number = "1********1" # 一個一個輸入增加模仿用戶登錄 for num in number:login_name.send_keys(num)time.sleep(0.3) # 查詢密碼元素 login_pwd = driver.find_element_by_id("fm-login-password") # 輸入密碼 pwd = "********" for p_num in pwd:login_pwd.send_keys(p_num)time.sleep(0.3)# 查詢登錄按鈕 login = driver.find_element_by_xpath("//button[@type='submit']") login.click() time.sleep(5) login_out = driver.find_element_by_id("J_Logout") login_out.click() driver.back() time.sleep(2) details = driver.find_element_by_class_name("product-iWrap") details.click() time.sleep(3) # 轉到新窗口 windows = driver.window_handles driver.switch_to.window(windows[-1]) time.sleep(3) content = driver.page_sourcewith open("./產品詳細.html", "w", encoding="utf-8") as file:file.write(content) time.sleep(12) print("產品詳細頁已經保存完畢!!!!") driver.quit()登陸成功后退出賬號也可以繼續爬取網站內容,之所以退出是防止后面被他發現俺是爬他東西的機器人然后把俺賬號封了!!!!
?模擬視頻:
selenium模擬登錄天貓淘寶網站
總結
以上是生活随笔為你收集整理的Selenium滑块验证登录天猫淘宝网站的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++-实现matlab的cart2po
- 下一篇: 简单描述微信支付pay