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