phantomjs和selenium模拟登陆qq空间

# -*- coding: utf-8 -*-
from selenium import webdriver
import time

driver =webdriver.PhantomJS()
driver.maximize_window()

def get_shuoshuo():
    driver.get('https://user.qzone.qq.com/177472465')

    try:
        driver.find_element_by_id('login_div')
        a = True
    except:
        a = False

    if a==True:
        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('29')
        driver.find_element_by_id('p').clear()
        driver.find_element_by_id('p').send_keys('we2')
        driver.find_element_by_id('login_button').click()
        time.sleep(3)
    driver.implicitly_wait(3)

    try:
        driver.find_element_by_id('QM_OwnerInfo_Icon')
        b = True
    except:
        b = False


    if b==True:
        time.sleep(3)
        driver.switch_to.frame('QM_Feeds_Iframe')
        content =driver.find_element_by_id('host_home_feeds').get_attribute('innerHTML')
        print content
    driver.close()
    driver.quit()

if __name__ == '__main__':
    get_shuoshuo()

https://zhuanlan.zhihu.com/p/25006226

原文地址:https://www.cnblogs.com/norm/p/7448990.html