Submitting values and clicking buttons in IE

本文详细介绍了如何利用win32com.client库中的Dispatch函数创建并控制InternetExplorer.Application实例,实现与MicrosoftInternetControls(1.1)对象库的早期绑定。通过代码示例展示了如何导航到网页、等待页面加载完成、获取文档、处理表单提交等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
# Use the makepy utility for the "Microsoft Internet Controls (1.1)"
# object library to get early binding.
from win32com.client import Dispatch
from time import sleep
 
ie = Dispatch("InternetExplorer.Application")  #Create browser instance.
ie.Visible = 1      # Make it visible (0 = invisible)
ie.Navigate("http://www.google.com")
while ie.ReadyState != 4:    # Wait for browser to finish loading.
    sleep(1)
 
doc = ie.Document   # Get the document.
while doc.readyState != "complete": # Wait for document to finish
    sleep(1)
   
doc.f.q.value = "qwerty"    # form name is 'f'; search field name is 'q'
doc.f.submit()  # Submits form using default button (in this case, btnG)
# OR alternatively you can specify which button to click as follows...
# doc.f.btnI.click()    # click on button 'btnI'
 
# Note:  You can also reference the forms by the order in which they
# appear in the forms collection.  For example, you could use the
# following code as well which references the first form.
# doc.forms[0].q.value = 'qwerty'

from: http://win32com.goermezer.de/content/view/168/187/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值