# -*- coding: gb2312 -*-from PAM30 import PAMIEfrom 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 dictdict = 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.parentWindowpwindow.execScript('NewArticle()')#===============================================================================# 设置文章标题,文章分类,系统分类,文章类型#===============================================================================mainFrame = ie.getFrame('main')doc = mainFrame.document#------------------------------------------------------------------------ 设置文章标题doc.getElementById('blog_title').value = dict['title']#------------------------------------------------------------------------ 文章分类-javadoc.getElementById('frmid').value = '119124'#------------------------------------------------------------------------ 系统分类-javadoc.getElementById('systemfrmid').value = '20'#----------------------------------------------------------------------- 文章类型-原创doc.getElementById('arttype').value = dict['arttype']#===============================================================================# 填写文章内容#===============================================================================pwindow = mainFrame.document.parentWindowpwindow.execScript('InsertHTML("Python+PAMIE")')pwindow.execScript('InsertHTML("如此强大的功能")')#===============================================================================# 发表文章#===============================================================================pwindow.execScript('savearticle()')