Selenium滑块验证登录天猫淘宝网站

该博客介绍了如何使用Selenium库模拟登录天猫网站,绕过滑块验证,搜索商品,填写登录信息,点击登录,然后爬取并保存商品详情页面的内容。在登录后退出账号以避免被识别为爬虫。

模拟登录天猫和淘宝网址,直接跳过滑块验证的方法。

import time

from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions

option = 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])
# 查询用户
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CJ.Williams

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值