2

我们公司使用基于浏览器的程序进行业务运营。我的目标是自动从这个系统中获取一些数据。

该网站本身大量使用框架,但我处理得相当体面。现在摆在我面前的问题是导航到存放我的数据的屏幕。

链接本身是用 javascript 编码的,我没有看到锚标记 (图像是 +/-,或者间距不可见)

源代码

<div id='Nav_4' aTag='aTarget'  title='Target' aUrl="javascript:top.aaa.submitPage('NavigateTo','~/aPages/aPage.aspx?UC=a')">
 <img alt='' style="margin-left:0px; width:0px "/>
 <img src='/a/a.axd?d=a' alt='(Collapsed)' aAltX='(Expanded)' imgType='exp' />
 <img alt=''style='width:5px; visibility:hidden;'>
<span atxt='1' class="   breadcrumbTreeItem">
 Target
</span></div>

由于我无法获得 a 标签,或在文档中搜索链接,因此我尝试找到包含“目标”的跨度标签并尝试激活它。

这是工作代码! (i5 是一个迭代器)

Set ie = GetOpenIEByURL("https://aaa.com/AAA.htm")
fIter = 0
 For Each frmSet In ie.document.getElementsByTagName("Frame")
  If Left(frmSet.src, 7) = "aaa/AAA" Then
   myFrame = f_Iter
   Exit For
  End If
f_Iter = f_Iter + 1
Next

With ie
 For i5 = 0 To ie.document.frames(myFrame).document.all.tags("SPAN").Length - 1
  With .document.frames(myFrame).document.all.tags("SPAN").Item(i5)
   If InStr(.innerText, "Target") > 0 Then
    .Click
    Exit For
   End If
  End With
 Next i5
End With

此外,在模块中,添加以下代码:

'Finds an open IE site by checking the URL
Function GetOpenIEByURL(ByVal i_URL As String) As InternetExplorer
Dim objShellWindows As New ShellWindows

  'ignore errors when accessing the document property
  On Error Resume Next
  'loop over all Shell-Windows
  For Each GetOpenIEByURL In objShellWindows
    'if the document is of type HTMLDocument, it is an IE window
    If TypeName(GetOpenIEByURL.document) = "HTMLDocument" Then
      'check the URL
      If Left(GetOpenIEByURL.document.URL, 30) = Left(i_URL, 30) Then
        'leave, we found the right window
        Exit Function
      End If
    End If
  Next
End Function
4

1 回答 1

0

看你的代码,我明白了

elementList = ie.document.frames(myFrame).document.getElementsByTagName("span")

应该与 一起使用Set,如下所示:

Set elementList = ie.document.frames(myFrame).document.getElementsByTagName("span")

至于Dim在线上的错误,您始终可以将其定义为ObjectorVariant并且这应该仍然有效,因为返回的类型getElementsByTagName应该仍然有效。


响应您的更新,单击按钮,我使用:

Set objButton = IEPage.getelementbyid("buttonname")
IEPage.onmousedown 'There is JS code that catches these actions for validation, so we artificially trigger them on the page. Your requirements may vary.
objButton.Focus
objButton.Click

与您的代码混合,我会像这样把它放在一起(未经测试):

With ie
 For i5 = 0 To ie.document.frames(myFrame).document.all.tags("SPAN").Length - 1
  With .document.frames(myFrame).document.all.tags("SPAN").Item(i5)
   If InStr(.innerText, "Target") > 0 Then
    Debug.Print .innerText
    ie.document.frames(myFrame).document.onmousedown
    .Focus
    .Click
    Exit For
   End If
  End With
 Next i5
End With
于 2013-05-21T14:16:02.240 回答