美文网首页编程之美-Pyhon我爱编程
python学习之自动登录网页

python学习之自动登录网页

作者: 青青_fd08 | 来源:发表于2018-06-21 15:09 被阅读102次

    用到火狐的webdriver有点麻烦。
    1.首先要去载geckodriver-v0.21.0-win64
    地址:https://github.com/mozilla/geckodriver/releases
    2.然后将gecodriver.exe放到和python.exe一个目录下
    3.接着配置环境变量,将火狐安装目录C:\Program Files (x86)\Mozilla Firefox也配置到环境变量path中
    '''
    from selenium import webdriver
    import time
    from urllib.request import urlopen
    from bs4 import BeautifulSoup

    def auto_login():
    username = "admin"
    password = "admin"

    url ="http://10.96.1.50:8089/spc/spc_logonPage.do"
    brower = webdriver.Firefox()
    brower.get(url)
    time.sleep(3)
    brower.find_element_by_name('username').send_keys(username)
    brower.find_element_by_id('password').send_keys(password)
    brower.find_element_by_name('Login').click()
    time.sleep(3)
    brower.find_element_by_xpath(".//*[@id='cssmenu']/ul/li[8]").click()  # 登录
    time.sleep(2)
    brower.close()
    

    if name == 'main':
    for i in range(1,10):
    auto_login()
    '''

    相关文章

      网友评论

        本文标题:python学习之自动登录网页

        本文链接:https://www.haomeiwen.com/subject/lboqyftx.html