随笔 - 41, 文章 - 8, 评论 - 8, 引用 - 0
数据加载中……

[学习]使用python操作ie

以前写过一个使用python的urllib操作的登录脚本。
今天逛着发现,在windows下可以用win32com操作。
参考文章:
http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx
http://www.quou.cn/archives/234
下面是代码,登录人人的:
# -*- coding: utf-8 -*- 
"""
http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx
http://www.quou.cn/archives/234
"""
import win32com.client 
import time 
import getpass
ie
=win32com.client.DispatchEx("InternetExplorer.Application"
ie.Navigate(
"http://renren.com/"
ie.Visible
=1 
while ie.Busy: 
    time.sleep(
1
 
document
=ie.Document
body
=document.body
myElements
=[]
for i in body.getElementsByTagName("input"):
    
if str(i.getAttribute("id")) in ['email','password','login']:
        myElements.append(i)
for j in myElements:
    
if str(j.getAttribute("id"))=="email":
        j.value
="lintao51@163.com"
    
elif str(j.getAttribute("id"))=="password":
        j.value
=getpass.getpass()
    
else:
        j.click()

因为随便的,所以看起来不够简洁。

posted on 2011-02-03 18:05 mirguest 阅读(715) 评论(0)  编辑 收藏 引用 所属分类: Python


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理