1. 程式人生 > >python的splinter實現瀏覽器操作

python的splinter實現瀏覽器操作

python splinter

import time
from splinter import Browser
import win32api

def splinter(url):
    #open the chrome browser,need to download the chrome driver
    #browser = Browser('chrome')
    browser = Browser()
    #login 126 email websize
    browser.visit(url)
    #wait web element loading
    time.sleep(5)
    #fill in account and password
    browser.find_by_id('idInput').fill('xxxxxx')
    browser.find_by_id('pwdInput').fill('xxxxx')
    #click the button of login
    #browser.find_by_id('loginBtn').click()
    time.sleep(2)
    #the number of key 'F11' is 122
    win32api.keybd_event(122,0,0,0)
    #close the window of brower
    #browser.quit()

if __name__ == '__main__':
    websize3 ='http://www.126.com'
    splinter(websize3)