Splinter自动登录

默认用foxfire浏览器,如果用chrome请到官网下载 chromedriver驱动,解压后放到python目录scripts下 然后添加环境变量,在Path下添加chromedrvier的路径。

 

#import time
from splinter import Browser
def splinter(url):
    browser = Browser('chrome')
    browser.visit(url)
    #time.sleep(5)
    browser.find_by_id('Username').fill('userid')
    browser.find_by_id('Password').fill('userpassword')
    browser.find_by_id('LoginButton').click()
    info = []
    try:
        errinfo = browser.find_by_id('Error')
        errinfo = errinfo.text
        info.append(errinfo)
        print (info[5])
    except:
        print("Sucessful!")
    #time.sleep(0)  
    browser.quit()
  

 
if __name__=='__main__':
        website='http://url'
        splinter(website)

  

posted @ 2019-09-04 15:27  tec2019  阅读(332)  评论(0编辑  收藏  举报