python basic programming: the use of python Selenium automatic landing Jingdong gold collar sign function

Today we are speaking about how to achieve automatic landing Jingdong, collect coins and attendance by python. Graphic examples described herein combined to tell you in great detail, has a certain value for references, refer to the next friend in need of it
how automatic landing Jingdong?

We first look at Jingdong landing page, as shown below:

[Insert images, landing pages] Here Insert Picture Description
login box is the right of this box, but now we encounter a sleepy na, the default landing approach landing is scan code, if we want to log in as a public user, password, it is necessary switching it.

We look at how these two landing mode is switched, the element check your browser's passed, we look at the two labels.

[Insert Picture two landing method]
Here Insert Picture Description
scan code and the user login are landing in a div tag inside, we can select user login through css selector, so class following a label is checked, the next everything is more simple.

We want to get the input box to the user name, password and login button input box.

[Insert images, user login box] Here Insert Picture Description
The following look at the code to achieve, assuming we landed by FireFox browser simulate it.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time
login_url='https://passport.jd.com/uc/login'
uid='********'
pwd='********'
browser=webdriver.Firefox()
wait=WebDriverWait(browser, 10)
def login():
  try:
    browser.get(login_url)
    login_tab_u=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.login-tab:nth-child(3)")))
    login_tab_u.click()#这里我们没有获取那个a标签,而是直接获取外层的div标签,比较简单而且方便
    uid_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#loginname")))
    pwd_input=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#nloginpwd")))
    login_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#loginsubmit")))
    uid_input.send_keys(uid)
    pwd_input.send_keys(pwd)
    login_button.click()
  except TimeoutException:
    login()
def main():
  login()
  time.sleep(5)
  browser.close()
if __name__=='__main__':
  main()

How to automatically sign gold collar?

Vip gold collar must login page can.

url vip page = 'https: //vip.jd.com/home.html'

But to vip landing page, then it will jump to the landing page first step, the first step of the method we use to login.

[Insert a picture, sign Page to Here Insert Picture Description
sign on the right side of the link, click on this link to get us on the line.

[Insert images, links] sign
Here Insert Picture Description
this label is very simple.

vip_url='https://vip.jd.com/home.html'
def user_singin():
  try:
    browser.get(vip_url)
    login_tab_u=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.login-tab:nth-child(3)")))
    login_tab_u.click()
    uid_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#loginname")))
    pwd_input=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#nloginpwd")))
    login_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#loginsubmit")))
    uid_input.send_keys(uid)
    pwd_input.send_keys(pwd)
    login_button.click()
    sign_in_button=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#signIn")))
    sign_in_button.click()
    print('您已签到成功!')
  except TimeoutException:
    user_singin()

The preceding code with the above is the same, but the sign of the tab to get to.
I write to you, for everyone to recommend a very wide python learning resource gathering, click to enter , there is a senior programmer before learning to share experiences, study notes, there is a chance of business experience, and for everyone to carefully organize a python zero the basis of the actual project data, daily python to you on the latest technology, prospects, learning needs little comment on the details of
this landing approach basically be used on any website, just make a few changes on it.

to sum up

The above is the use of python Selenium automatic landing Jingdong gold collar sign function, we want to help small series to tell you, if you have any questions please give me a message, Xiao Bian will promptly reply to everyone.

Published 20 original articles · won praise 4 · views 20000 +

Guess you like

Origin blog.csdn.net/haoxun11/article/details/104931697