我是靠谱客的博主 糟糕月饼,这篇文章主要介绍Selenium滑块验证登录天猫淘宝网站,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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]) # 查询用户登录名输入框 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_source with open("./产品详细.html", "w", encoding="utf-8") as file: file.write(content) time.sleep(12) print("产品详细页已经保存完毕!!!!") driver.quit()

登陆成功后退出账号也可以继续爬取网站内容,之所以退出是防止后面被他发现俺是爬他东西的机器人然后把俺账号封了!!!!

 模拟视频:

selenium模拟登录天猫淘宝网站

最后

以上就是糟糕月饼最近收集整理的关于Selenium滑块验证登录天猫淘宝网站的全部内容,更多相关Selenium滑块验证登录天猫淘宝网站内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(94)

评论列表共有 0 条评论

立即
投稿
返回
顶部