python26工具[简历自动刷新器]

 

一 python + PAMIE

 

PAMIE的全称是Python Automated Module For Internet Explorer,顾名思义,PAMIE是一个实现IE自动化的模块。PAMIE包含以下2个文件:

PAM30.py包含了基于IE的web的自动化测试。

winGuiAuto.py用来帮助实现Windows GUI程序的测试的自动化。

 

PAMIE 主页: http://sourceforge.net/projects/pamie/, 下载后将PAM30.py和winGuiAuto.py拷贝到python的lib目录下(例如C:\Python26\Lib)。

 

二 自动刷新zhaopin.com的简历

以下代码通过web自动化的技术在8:00到16:00间每隔30分钟刷新一次简历。

代码:

View Code
# -*- coding: utf-8 -*-
import time
import datetime
import PAM30

def refreshZhaoPin(loginname,password):
  ie
=PAM30.PAMIE("www.zhaopin.com")
  ie.setTextBox(
"loginname",loginname)
  ie.setTextBox(
"password",password)
  ie.clickButton(
"login_button_1")
  
  
# should use cp936, gbk or gb2312
  jianli = ie.getLink(unicode("简历中心",'cp936'))
  ie.clickHiddenElement(jianli)
  shuaxin 
= ie.getLink(unicode("刷新",'cp936'))
  ie.clickHiddenElement(shuaxin)
  tuichu 
= ie.getLink(unicode("退出",'cp936'))
  ie.clickHiddenElement(tuichu)
  ie.quit()  
  
def scheduleRefreshInWorkingHours(everyminutes, fun, loginname,loginpass):
  starttime 
= '08:00:00'
  endtime 
= '16:00:00'
  
  
while(1):
    currenttime = datetime.datetime.now().time().isoformat()
    
if currenttime > starttime and currenttime < endtime:
       print 'Refresh at:'+ datetime.datetime.now().isoformat()
       fun(loginname,loginpass)
       time.sleep(everyminutes 
* 60)

if __name__ == '__main__':
  scheduleRefreshInWorkingHours(
30, refreshZhaoPin, 'yourloginusername', 'yourloginpassword')

 

三 对以上的脚本的改进 

1)如果不想让ie窗口出现,则可以在PAM30.py中修改self._ie.Visible = 1为self._ie.Visible = 0;

2)需要修改PAM30.py中的函数clickLink,将isinstance(name, str) 改为isinstance(name,basestring) 来支持连接为中文时clickLink传入的unicode字符串;
3)需要修改PAM30.py中showDebugging为self.showDebugging = False;

修改后的代码如下:

# -*- coding: utf-8 -*-
import time
import datetime
import PAM30

def refreshZhaoPin(loginname,password):
  ie
=PAM30.PAMIE("www.zhaopin.com")
  ie.setTextBox(
"loginname",loginname)
  ie.setTextBox(
"password",password)
  ie.clickButton(
"login_button_1")
  
  
# should use cp936, gbk or gb2312
  ie.clickLink(unicode("简历中心",'gbk'))
  ie.clickLink(unicode(
"刷新",'gbk'))
  ie.clickLink(unicode(
"退出",'gbk'))
  ie.quit()
  
  
def scheduleRefreshInWorkingHours(everyminutes, fun, loginname,loginpass):
  starttime 
= '08:00:00'
  endtime 
= '16:00:00'
  
  
while(1):
    
print 'Refresh at:'+ datetime.datetime.now().isoformat()
    currenttime 
= datetime.datetime.now().time().isoformat()
    
if currenttime > starttime and currenttime < endtime:
       fun(loginname,loginpass)
       time.sleep(everyminutes 
* 60)

if __name__ == '__main__':
  scheduleRefreshInWorkingHours(
30, refreshZhaoPin, 'yourloginusername''yourloginpassword')

 

四 参考:

http://www.cnblogs.com/john2000/archive/2010/09/19/1830764.html

http://www.cnblogs.com/bluescorpio/tag/PAMIE/

 

完!

posted @ 2011-03-27 13:03  iTech  阅读(1587)  评论(0编辑  收藏  举报