这里我用一个例子模拟!
下边我写了一个简单的table页面
由于页面自动注释html代码,无法把代码贴出!我把<>都去掉
html
title
测试
/title
body
table
tr
td
aaa
/td
td
bbb
/td
td
ccc
/td
/tr
/table
/body
/html
保存html,运行效果如下
aaa bbb ccc
[ Last edited by pcl2004_27 on 2004-7-3 at 15:51 ]作者: pcl2004_27 时间: 2004-7-3 16:02
我用vb写的一个函数,你可以把它编成dll,加载到robot中!
代码如下
Function FindSucessString(byval url as string, byval strFind as String) as boolean
Dim ie as SHDocVw.InternetExplorer
Dim Doc as MSHTML.HTMLDocument
Dim td as MSHTML.HTMLBody
Dim tbl as MSHTML.HTMLTable
Dim r as MSHTML.HTMLTableRow
Dim c as MSHTML.HTMLTableCell
Dim i as integer
set IE = New SHDocVw.InternetExplorer
IE.Navigate url
Set doc = ie.document
set td = doc.body
for i = 0 to doc.all.length - 1
if UCASE(doc.all(i).tagName) ="TABLE" Then
Set tbl = doc.all(i)
for each r in tbl.rows
for each c in r.cells
if ucase(c.innertext) = strFind then
FindSucessString = true
exit Function
end if
next
next
end if
next
FindSucessString =False
Set doc =nothing
End Function
url是包含你要处理的table页面地址, strFind 是你需要对比的那个字符串
其实整个思路是,遍历table,对比cell的内容!
[ Last edited by pcl2004_27 on 2004-7-12 at 16:29 ]作者: pcl2004_27 时间: 2004-7-16 09:08
为了和robot中代码兼容,修改以上代码
Function FindSucessString(byval url as string, byval strFind as String) as integer
Dim ie as SHDocVw.InternetExplorer
Dim Doc as MSHTML.HTMLDocument
Dim td as MSHTML.HTMLBody
Dim tbl as MSHTML.HTMLTable
Dim r as MSHTML.HTMLTableRow
Dim c as MSHTML.HTMLTableCell
Dim i as integer
set IE = New SHDocVw.InternetExplorer
IE.Navigate url
Set doc = ie.document
set td = doc.body
for i = 0 to doc.all.length - 1
if UCASE(doc.all(i).tagName) ="TABLE" Then
Set tbl = doc.all(i)
for each r in tbl.rows
for each c in r.cells
if trim(c.innertext) = strFind then
FindSucessString = 1
exit Function
end if
next
next
end if
next
FindSucessString =0
Set doc =nothing
End Function
如果成功返回值为1,否则为0
经过测试我修改了table,中间如多种页面元素,比如input text等
你把以上代码修改为dl,主意要引用两个对象mshtml ,mircosoft internet control两个对象!然后编译。
然后注册该dll,再robot中引用就可以了