Use Python+selenium to simulate login QQ space

Source: Internet
Author: User

Crawl QQ space and so on most of the pages need to login, research QQ login rules, have to analyze a large number of JavaScript encryption decryption, this can definitely drop a few pounds of hair. And now with the Selenium tool, MA Ma no longer need not worry about your QQ login!

Selenium is a Web automation testing tool, it runs directly instantiate a browser, fully simulate the user's operation, such as clicking on the link, input form, click the button to submit. So we use it can be very convenient to login QQ space.
#导入selenium2中的webdriver库

From selenium import Webdriver

#实例化出一个Firefox浏览器
Driver = Webdriver. Firefox ()

#设置浏览器窗口的位置和大小
Driver.set_window_position (20, 40)
Driver.set_window_size (1100,700)

#打开一个页面 (QQ space login page)
Driver.get (' http://qzone.qq.com ')
#登录表单在页面的框架中, so to switch to the frame
Driver.switch_to_frame (' Login_frame ')
#通过使用选择器选择到表单元素进行模拟输入和点击按钮提交
driver.find_element_by_id (' Switcher_plogin '). Click ()
driver.find_element_by_id (' U '). Clear ()
driver.find_element_by_id (' u '). Send_keys (' 917464311 ')
driver.find_element_by_id (' P '). Clear ()
driver.find_element_by_id (' P '). Send_keys (' 123456 ')
driver.find_element_by_id (' Login_button '). Click ()

#do something ....
#退出窗口
Driver.quit ()

This can be convenient to login to the QQ space, the next step can use this login status to crawl page content or other brain hole open application ~ ~ ~
To install the Selenium library, it is recommended that you use the PIP tool directly

#pip Install Selenium

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.