Python realizes QQ Auto-likes

Source: Internet
Author: User
Tags xpath selenium chromedriver

Use Python to do a QQ automatic point like artifact, on the code:

1 def Qqzan (QQ): 2     browser = Webdriver. Chrome () 3     Browser.maximize_window () 4     browser.get (' Https://user.qzone.qq.com/{}/main '. Format (QQ)) 5     Browser.switch_to_frame (' Login_frame ') 6     #通过使用选择器选择到表单元素进行模拟输入和点击按钮提交 7     browser.find_element_by_id (' Switcher_plogin '). Click () 8     browser.find_element_by_id (' U '). Clear () 9     browser.find_element_by_id (' U '). Send_keys (' Fill your QQ account here ')     browser.find_element_by_id (' P '). Clear () One-     browser.find_element_by_id (' P '). Send_keys (' Fill in your QQ password here ')     browser.find_element_by_id (' Login_button '). Click () +     Time.sleep (3)     Browser.find_element_by_xpath ('//*[@id = ' like ']/a[1] '). Click ()     browser.quit ()

Here defines a function, enter the QQ number can directly login TA's space to point to praise. I am using the Chrome browser to operate, it is recommended that you use Firefox. If everyone and I are using chrome, need to download a corresponding version of your selenium chromedriver.exe, need to download can go to csdn to see, be sure to download the corresponding version. After downloading, put Chromedriver.exe in your Python installation directory.

The code is simple, open the Chrome browser, maximize the window, enter the space you want to access, enter your account and password to log in, click the Like button, and then close the browser. To note that, I am here is a lite version, no judgment did not do exception processing, such as may you open the Web page, but some things did not load out you will directly find the input, certainly can not find, the end will not succeed, generally wait a few seconds, or determine whether it has been loaded successfully (with dynamic wait). There are many ways to locate, there is not much to say, the Internet is very clear, you first open the browser, the mouse to the corresponding position, such as the input box, right click, open check, such as:

  

Through these basic can be located, some do not have these attribute, but also through Xpath, such as positioning, the operation is as follows: Before checking the found code there right-->> copy-->> Copy Xpath (other similar)

The complete code is as follows:

1 def Qqzan (QQ): 2     browser = Webdriver. Chrome () 3     Browser.maximize_window () 4     browser.get (' Https://user.qzone.qq.com/{}/main '. Format (QQ)) 5     Browser.switch_to_frame (' Login_frame ') 6     #通过使用选择器选择到表单元素进行模拟输入和点击按钮提交 7     browser.find_element_by_id (' Switcher_plogin '). Click () 8     browser.find_element_by_id (' U '). Clear () 9     browser.find_element_by_id (' U '). Send_keys (' Fill in your QQ number here ')     browser.find_element_by_id (' P '). Clear () One-     browser.find_element_by_id (' P '). Send_keys (' Fill in your QQ password here ')     browser.find_element_by_id (' Login_button '). Click ()     time.sleep (3)     Browser.find_element_by_xpath ('//*[@id = ' like ']/a[1] '). Click () browser.quit ()     Qqzan (' Want to order the QQ number ')

Python realizes QQ Auto-likes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.