In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to automatically log in to Taobao Selenium login loophole analysis, the article is rich in content and professional analysis and description for you, after reading this article, I hope you can get something.
I. Preface
Before manually logging in to Taobao to enable the browser to save my information, and then using the local user configuration to control the browser, opportunely solved the login problem.
Although this is a method, but it makes selenium fully automatic into semi-automatic, not worthy of the beauty of Python.
So how to log on to Taobao automatically? At first, I was looking for some resource projects on the Internet and analyzed them directly, but with the enhancement of Taobao's anti-crawling mechanism, none of their methods worked. So I decided to do it myself!
2. Analysis
For ease of use, I encapsulated the entire code, the file name is login, the class name is Login, please read on.
1) dependent from selenium.webdriver.support import expected_conditions as EC
From selenium.webdriver.support.wait import WebDriverWait
From selenium.common.exceptions import TimeoutException
From selenium.webdriver.common.keys import Keys
From selenium.webdriver import ActionChains
From selenium.webdriver.common.by import By
From selenium import webdriver
Import time
2) Constructor def _ _ init__ (self, username, password):
"
Initialize browser configuration and login information
"
Self.url = 'https://login.taobao.com/member/login.jhtml'
# initialize browser options
Options = webdriver.ChromeOptions ()
# prohibit loading of pictures
Options.add_experimental_option ("prefs", {"profile.managed_default_content_settings.images": 2})
# set to developer mode
Options.add_experimental_option ('excludeSwitches', [' enable-automation'])
# load browser options
Self.browser = webdriver.Chrome (options=options)
# set explicit wait time of 40s
Self.wait = WebDriverWait (self.browser, 40)
Self.username = username # user name
Self.password = password # password
3) original login, log in to def original (self) using Taobao account or mobile phone number:
"
Log in directly using Taobao account
: return: None
"
Self.browser.get (url=self.url)
Try:
Input_username = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.fm-field > div.input-plain-wrap.input-wrap-loginid > input'
))
Input_password = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.fm-field > div.input-plain-wrap.input-wrap-password > input'
))
# wait for the slider button to load
Div = self.wait.until (EC.presence_of_element_located (
By.ID, 'nc_1__bg'
))
Input_username.send_keys (self.username)
Input_password.send_keys (self.password)
# hibernate for 2s and wait for the slider button to load
Time.sleep (2)
# Click and hold the slider
ActionChains (self.browser). Click_and_hold (div). Perform
# move the slider
ActionChains (self.browser). Move_by_offset (xoffset=300, yoffset=0). Perform ()
# waiting for verification to pass
Self.wait.until (EC.text_to_be_present_in_element (
By.CSS_SELECTOR, 'div#nc_1__scale_text > span.nc-lang-cnt > b'),' verified'
))
# Login
Input_password.send_keys (Keys.ENTER)
Print ('Successful!')
Except TimeoutException as e:
Print ('Error:', e.args)
Self.original ()
I will not say much about the positioning of other node elements, but mainly talk about the positioning of the slider.
If you use the browser to locate, you will navigate to the span node, but after I imitate clicking and holding down, the slider does not move and the parameters do not change. So I tried whether its parent node, div, was held down and dragged, and this time it worked. So sometimes don't doubt your code, it may be something else.
Also on the drag and drop also note that Taobao login verification is not the extreme verification code, not the operation of dragging the slider puzzle, but dragging the slider to the far right. So, as for the rightmost end, as long as the distance is long enough and does not exceed the scope of the interface, the length can be arbitrarily determined!
Finally, I would add that this happens occasionally.
It is not easy to get this picture, because this situation is really too rare. After repeated experiments, it is probably because the sliding trajectory is not caused by the basic level, that is, sliding downwards, although it can also reach the rightmost end, it will give this error. My program is to slide it horizontally by 300 and its vertical coordinates to zero. Although it is a horizontal slide, a wait for verification is added in order to improve the fault tolerance of the program.
4) use the Sina Weibo account to log in to exploit the loophole cleverly
Tip: please bind your Sina account on Taobao before logging in with Sina Weibo.
Def sina (self):
"
Log in using your Sina Weibo account (bind your Sina account in advance)
: return: None
"
Self.browser.get (url=self.url)
Try:
# waiting for Sina login link to load
Weibo_login = self.wait.until (EC.element_to_be_clickable (
By.CSS_SELECTOR,'# login-form a.Weibomuri login'
))
Weibo_login.click ()
Input_username = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.info_list > div.inp.username > input.W_input'
))
Input_password = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.info_list > div.inp.password > input.W_input'
))
Input_username.send_keys (self.username)
Input_password.send_keys (self.password)
Input_password.send_keys (Keys.ENTER)
# wait for the browser to save our information. If the network speed is not good, you can set it a little longer.
Time.sleep (5)
# refresh the page
Self.browser.refresh ()
# wait for the Quick Login button to load
Quick_login = self.wait.until (EC.element_to_be_clickable (
By.CSS_SELECTOR, 'div.info_list > div.btn_tip > a.Whibtningg'
))
Quick_login.click ()
Print ('login successful!')
Except TimeoutException as e:
Print ('Error:', e.args)
Self.sina ()
I will not say much about the location of node elements, but mainly talk about this loophole.
Under normal circumstances, after entering the information, click login, it is time to enter the Taobao page, but no matter how the login button, the page is indifferent.
If you locate it, you can find:
The link to this button is _ javascript:void (0), fake link!
Because my front-end foundation is not good, I don't know what this means. I frantically searched the Internet to find out how to use selenium to click on this link, but I still couldn't find a solution. Does anyone know how to deal with this? please leave a message for the original author!
However, when I was about to give up, I pressed F5 to refresh, and there was a miracle!
Detected the logged in Weibo account, quickly log in? It turns out that although I did not enter Taobao, the lower left corner of the browser has been displaying information such as: waiting for * * corresponding, parsing host and other information. So Taobao still saved my account information, as long as the next automatic login check (default check), it will save the account information.
This is why the above code, after entering the information and entering the enter to log in, has to wait 5 seconds to save my account information.
Finally, refresh the page, click to log in quickly, and you are done!
3. Complete code and usage 1) complete code #-*-coding: utf-8-*-
"
@ author:Pineapple
@ contact:cppjavapython@foxmail.com
@ time:2020/7/28 9:09
@ file:login.py
@ desc: login taobao.
"
From selenium.webdriver.support import expected_conditions as EC
From selenium.webdriver.support.wait import WebDriverWait
From selenium.common.exceptions import TimeoutException
From selenium.webdriver.common.keys import Keys
From selenium.webdriver import ActionChains
From selenium.webdriver.common.by import By
From selenium import webdriver
Import time
Class Login:
Def _ _ init__ (self, username, password):
"
Initialize browser configuration and login information
"
Self.url = 'https://login.taobao.com/member/login.jhtml'
# initialize browser options
Options = webdriver.ChromeOptions ()
# prohibit loading of pictures
Options.add_experimental_option ("prefs", {"profile.managed_default_content_settings.images": 2})
# set to developer mode
Options.add_experimental_option ('excludeSwitches', [' enable-automation'])
# load browser options
Self.browser = webdriver.Chrome (options=options)
# set explicit wait time of 40s
Self.wait = WebDriverWait (self.browser, 40)
Self.username = username # user name
Self.password = password # password
Def original (self):
"
Log in directly using Taobao account
: return: None
"
Self.browser.get (url=self.url)
Try:
Input_username = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.fm-field > div.input-plain-wrap.input-wrap-loginid > input'
))
Input_password = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.fm-field > div.input-plain-wrap.input-wrap-password > input'
))
# wait for the slider button to load
Div = self.wait.until (EC.presence_of_element_located (
By.ID, 'nc_1__bg'
))
Input_username.send_keys (self.username)
Input_password.send_keys (self.password)
# hibernate for 2s and wait for the slider button to load
Time.sleep (2)
# Click and hold the slider
ActionChains (self.browser). Click_and_hold (div). Perform
# move the slider
ActionChains (self.browser). Move_by_offset (xoffset=300, yoffset=0). Perform ()
# waiting for verification to pass
Self.wait.until (EC.text_to_be_present_in_element (
By.CSS_SELECTOR, 'div#nc_1__scale_text > span.nc-lang-cnt > b'),' verified'
))
# Login
Input_password.send_keys (Keys.ENTER)
Print ('Successful!')
Except TimeoutException as e:
Print ('Error:', e.args)
Self.original ()
Def sina (self):
"
Log in using your Sina Weibo account (bind your Sina account in advance)
: return: None
"
Self.browser.get (url=self.url)
Try:
# waiting for Sina login link to load
Weibo_login = self.wait.until (EC.element_to_be_clickable (
By.CSS_SELECTOR,'# login-form a.Weibomuri login'
))
Weibo_login.click ()
Input_username = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.info_list > div.inp.username > input.W_input'
))
Input_password = self.wait.until (EC.presence_of_element_located (
By.CSS_SELECTOR, 'div.info_list > div.inp.password > input.W_input'
))
Input_username.send_keys (self.username)
Input_password.send_keys (self.password)
Input_password.send_keys (Keys.ENTER)
# wait for the browser to save our information. If the network speed is not good, you can set it a little longer.
Time.sleep (5)
# refresh the page
Self.browser.refresh ()
# wait for the Quick Login button to load
Quick_login = self.wait.until (EC.element_to_be_clickable (
By.CSS_SELECTOR, 'div.info_list > div.btn_tip > a.Whibtningg'
))
Quick_login.click ()
Print ('login successful!')
Except TimeoutException as e:
Print ('Error:', e.args)
Self.sina ()
2) use
Import the Login class when you use it, then initialize the class, and finally the login method uses the corresponding function, the file name is login, and the class name is Login.
From login import Login
Username ='*'# account
Password ='*.'# password
# initialize the Login class
Login = Login (username, password)
# Log in using Taobao account or mobile number
Login.original ()
# Log in using your Sina Weibo account
# login.sina ()
The above is the editor for you to share how to carry out Selenium automatic login Taobao login loophole analysis, if there happen to be similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.