想想我曾是狐友啊,放弃多年了 最近为了种菜偷菜,想用VFP写个小软件,想再学习下,找到赵老师一票好帖子,特意收藏下:
http://bbs./dispbbs.asp?boardid=81&replyid=291222&id=62506&skin=0&page=1&star=2
QTE
写这个帖子,是为了与 abiao 交流一下,也告诉FOXER一个技巧,即如何写程序操作已打开的网页,这个方法两、三年前我就摸索掌握了,对我而言也是一个秘籍,现奉献给大家,希望大家给我一个好评吧!!!
关键知识点:
1、获得SHELL对象
oshell=createobject("shell.application")
2、获得WINDOW()对象,此对象包含所有打开的网页与文件夹对象
ow=oshell.windows()
下面贴出我写的程序,用于读写某网页(已打开的登机易)
oshell=createobject("shell.application")
ow=oshell.windows()
ffound=.f.
if ow.count>0
for i=0 to (ow.count-1)
if ("IEXPLORE.EXE" $ UPPER(ow.item(i).fullname))
if ow.item(i).document.title="登机易"
if ffound
=messagebox("请只打开一个登机易网页!")
exit for
endif
thisform.text2.value=ow.item(i).document.getElementById("Detail_Grid").rows(1).cells(2).innertext
ct3=ow.item(i).document.getElementById("Slrq_Txt").value
thisform.text3.value=ctod(ct3)
thisform.text5.value=ow.item(i).document.getElementById("Detail_Grid").rows(1).cells(0).innertext
ct6=ow.item(i).document.getElementById("Clxr_Txt").value
thisform.text6.value=ct6
ct8=ow.item(i).document.getElementById("Lxdh_Txt").value
thisform.text8.value=ct8
ct7=ow.item(i).document.getElementById("Khdz_Txt").value
thisform.text7.value=ct7
otable=ow.item(i).document.getElementById("Detail_Grid")
thisform.text9.value=otable.rows(1).cells(6).innertext
thisform.text10.value=otable.rows(1).cells(3).innertext
thisform.text11.value=otable.rows(1).cells(4).innertext
thisform.text12.value=otable.rows(1).cells(5).innertext
thisform.text13.value=otable.rows(1).cells(7).innertext
qtxt=otable.rows(1).cells(8).innertext
thisform.text14.value=ctod(substr(qtxt,1,4)+"/"+substr(qtxt,5,2)+"/"+substr(qtxt,7,2))
thisform.text15.value=otable.rows(1).cells(9).innertext
thisform.text17.value=val(otable.rows(1).cells(10).innertext)
thisform.text19.value=50
thisform.text20.value=val(otable.rows(1).cells(11).innertext)-50
thisform.edit1.value=ow.item(i).document.getElementById("Khyq_Txt").value
sfz=otable.rows(1).cells(1).innertext
sldh=ow.item(i).document.getElementById("Sldh_Txt").value
****pdry 派单人员
pdry=ow.item(i).document.getElementById("Pdry_Txt").value
pdrq=ow.item(i).document.getElementById("Pdrq_Txt").value
wystr=ow.item(i).document.body.innertext
wystr=strtran(wystr,"受理单号:","受理单号:"+sldh)
wystr=strtran(wystr,"受理日期:","受理日期:"+ct3)
wystr=strtran(wystr,"派单日期:","派单日期:"+pdrq)
wystr=strtran(wystr,"派单人员:","派单人员:"+pdry)
wystr=strtran(wystr,"联系人 :","联系人 :"+ct6)
wystr=strtran(wystr,"联系电话:","联系电话:"+ct8)
wystr=strtran(wystr,"客户地址:","客户地址:"+ct7)
ffound=.T.
endif
endif
endfor
endif
rele oshell
rele ow
if ffound=.f.
=messagebox("没有已打开的登机易网页!")
endif
thisform.edit1.setfocus
return
UNQTE
【ow.item(i).document.getElementById("Detail_Grid").rows(1).cells(2).innertext】这是读网页中ID为"Detail_Grid"的.表格中第2行第3列的内客。
如网页表单中的输入框的ID为"Khdz_Txt"是客户地址输入框,以下这条语句就可给它录入信息。
ow.item(i).document.getElementById("Khdz_Txt").value="海口市海甸岛"
大家可以测试一下,看搜索输入框中是否输入了内容
1、打开网易的主页 WWW.163.com
2、运行以下代码
oshell=createobject("shell.application")
ow=oshell.windows()
ffound=.f.
if ow.count>0
for i=0 to (ow.count-1)
if ("IEXPLORE.EXE" $ UPPER(ow.item(i).fullname))
if ow.item(i).document.title="网易"
if ffound
=messagebox("请只打开一个网易网页!")
exit for
ENDIF
*!* 在网易的搜索输入框中输入文本----梅子论坛VFP技巧
ow.item(i).document.getElementById("q").value="梅子论坛VFP技巧"
ffound=.T.
endif
endif
endfor
endif
rele oshell
rele ow
if ffound=.f.
=messagebox("没有已打开的网易网页!")
endif