Python3 + selenium to automate QQ Group Solitaire

If you need to reprint, please attach the original link, thank you for your cooperation.

1. Environment

The environment is configured as Python3 with the selenium module installed, and
if the driver corresponding to the browser is not installed with selenium, you can execute the following code in the console

pip3 install selenium

Browser driver download address: https://selenium-python.readthedocs.io/installation.html#drivers
need to select the corresponding version of the corresponding browser to download and
download, and then put it into the Python installation directory

Second, the code

Deficiency: Only one newly released group Solitaire can be used for automatic Solitaire

1  from selenium import webdriver
 2  import time
 3  import datetime
 4  
5 QQ = " fill in the QQ number here " 
6 password = " fill in the QQ password here " 
7 qun = " here fill in the QQ group number of Solitaire " 
8  
9 browser = webdriver.Firefox ()
 10  # If other browsers please refer to the documentation, such as Google browser is webdriver.Chrome () 
11 browser.get ( " https://i.qq.com/ " )   # login QQ QQ space by 
12 browser .switch_to.frame (" Login_frame " )   # switch to the web page login window 
13 is browser.find_element_by_id ( " switcher_plogin " ) .click ()
 14 the time.sleep (. 1 )
 15  # to clear the account and password box frame content 
16 browser.find_element_by_id ( ' U ' ) .clear ()
 . 17 browser.find_element_by_id ( ' P ' ) .clear ()
 18 is the time.sleep (. 1 )
 . 19  # automatically enter the QQ number and password 
20 is browser.find_element_by_id ( " U " ) .send_keys (QQ)
 21 isbrowser.find_element_by_id ( " the p- " ) .send_keys (password)
 22 the time.sleep (1 )
 23 browser.find_element_by_id ( " login_button " ) .click ()   # click the login button 
24- browser.switch_to.default_content ()   # to switch back to the main page 
25 url = " https://qun.qq.com/homework/qunsolitaire/list.html?_wv=1031&gc= " + qun + " & from = appstore_icon & from = qqminiprogram = " + qun + " & state = 1 " 
26  # will check in The web page writes in the variable url 
27  print(url)
 28  print ( " If the login is not successful, please automatically jump to the group solicitation webpage please visit the URL " )
 29  print ( " https://user.qzone.qq.com/ " )
 30  print ( " At the address above Finally add your QQ number " )
 31  while True:   # Determine whether the login is successful 
32      time.sleep (1) # To prevent too fast judgment caused the computer to
 freeze   , you can adjust 33      if browser.current_url == " https: / /user.qzone.qq.com/ " + QQ:
 34          print ( ' Login successful! ' )
35          BREAK 
36  the while True:
 37 [      browser.get (URL)
 38 is      the time.sleep (0.5)   # prevent excessive causing the computer determines Caton, can be adjusted 
39      STR = browser.find_element_by_xpath ( " / HTML / body / div / div [. 1] / div [. 1] / div [. 3] " ) .text
 40      # determines a solitaire has been completed the first 
41 is      iF STR == " has Solitaire "  or STR == " ended " :
 42 is          the time.sleep ( 1 )
 43          continue 
44      browser.find_element_by_xpath ( "/html/body/div/div[1]/div[1]/div[3]").click()
45     time.sleep(0.5)
46     browser.find_element_by_xpath("/html/body/div/div[2]/div/div[2]").click()
47     print(datetime.datetime.now().strftime('%Y%m%d %H%M%S 群接龙签到成功'))
48     time.sleep(1)

 

Guess you like

Origin www.cnblogs.com/hurentian/p/12702574.html