• [转]python pamie简介


    Python这种脚本语言的强大功能越来越被广大的程序员所重视,这种之前在国内流行度不高的语言近来气势高涨。各种第三方模块层出不穷。
     
    本文介绍的便是一种能非常方便操作IE的第三方工具,PAMIE,他能让你如同写JS一样来操作IE浏览器。包括自动启动,访问链接,设置文本框值,获取按钮,执行点击事件,甚至执行页面JS方法等等。下面用一个实际的例子详加说明:
     
    以下简短代码便轻易实现,登录本人ChinaUnix,并以此点击日志文章,发文章,设置标题,分类,和博客内容,最后执行确定,发布成功。
    # -*- coding: gb2312 -*-
    from PAM30 import PAMIE
    from string import split
    #===============================================================================
    # 从文件读取配置信息,登录url,账户,密码等
    #===============================================================================
    def getCfgFromFile(fileName='settings.txt'):
        file = open(fileName)
        dict = {}
        line = file.readline()
        while line != '':
            args = split(line, '=')
            dict[args[0]] = args[1].decode('utf-8').encode('gb2312')
            line = file.readline()
        return dict
    dict = getCfgFromFile()
    ie = PAMIE()
    #===============================================================================
    # 打开登录页面,设置用户/密码
    #===============================================================================
    ie.navigate(dict['login-url'])
    ie.setTextBox('username', dict['username'])
    ie.setTextBox('password', dict['password'])
    #===============================================================================
    # 获取登录按钮
    #===============================================================================
    loginbtn = ie.findElement('input', 'type', 'image')
    ie.clickElement(loginbtn)
    #===============================================================================
    # 点击文章管理
    #===============================================================================
    ie.navigate(dict["article-url"])
    #===============================================================================
    # 点击写文章
    #===============================================================================
    mainFrame = ie.getFrame('main')
    pwindow = mainFrame.document.parentWindow
    pwindow.execScript('NewArticle()')
    #===============================================================================
    # 设置文章标题,文章分类,系统分类,文章类型
    #===============================================================================
    mainFrame = ie.getFrame('main')
    doc = mainFrame.document
    #------------------------------------------------------------------------ 设置文章标题
    doc.getElementById('blog_title').value = dict['title']
    #------------------------------------------------------------------------ 文章分类-java
    doc.getElementById('frmid').value = '119124'
    #------------------------------------------------------------------------ 系统分类-java
    doc.getElementById('systemfrmid').value = '20'
    #----------------------------------------------------------------------- 文章类型-原创
    doc.getElementById('arttype').value = dict['arttype']
    #===============================================================================
    # 填写文章内容
    #===============================================================================
    pwindow = mainFrame.document.parentWindow
    pwindow.execScript('InsertHTML("Python+PAMIE")')
    pwindow.execScript('InsertHTML("如此强大的功能")')
    #===============================================================================
    # 发表文章
    #===============================================================================
    pwindow.execScript('savearticle()')
  • 相关阅读:
    Preserving Remote IP/Host while proxying
    使用EF Core生成实体类 用来作为NetCore数据库访问上下文 Context
    【ASP.NET Core快速入门】(八)Middleware管道介绍、自己动手构建RequestDelegate管道
    NetCore WebApi 基于Jwt的验证授权方式
    Net Core 页面的生命周期 + OnActionExecuting
    C# 多线程发送邮件 代码版
    ASP.NET Core 中的过滤器(Action过滤器,控制器过滤器,全局应用程序过滤器)
    深入理解 NetCore 中的依赖注入的好处 及 、Singleton、Scoped、Transient 三种对象的差异
    巧用 display: contents 增强页面语义
    巧妙实现带圆角的渐变边框
  • 原文地址:https://www.cnblogs.com/vigarbuaa/p/2553255.html
Copyright © 2020-2023  润新知