模拟登录天猫和淘宝网址,直接跳过滑块验证的方法。
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])
# 查询用户

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

被折叠的 条评论
为什么被折叠?



