问题描述
我们的公司使用业务运营一个基于浏览器的程序。我的目标是自动抓取一些数据出这个系统的。
Our company uses a browser-based program for business operations. My goal is to grab some data out of this system automatically.
该网站使用框架pretty严重,但我做pretty处理体面的。现在在我面前的问题是导航到上我的数据容纳在屏幕上。
The site itself uses frames pretty heavily, but I'm doing pretty decently handling that. The problem in front of me now is navigating to the screen on which my data is housed.
链接本身是在JavaScript $ C $光盘,我没有看到一个锚标记
的(图像是一个+/-,或间距不可见)的:
The link itself is coded in javascript, and I don't see an anchor tag(The image is a +/-, or invisible for spacing):
来源$ C $ C
<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>
因为我无法得到的一个标签,或搜索链接的文档,而不是我试图找到包含目标范围标记,并尝试将其激活。
Since I couldn't get the a tag, or search the document for Links, I instead tried to find the span tag that contained "Target" and try to activate it.
这里是工作code! (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
此外,在模块,添加此code:
Additionally, in the Module, add this code:
'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
推荐答案
看你的code,我看
Looking at your code, I see
Set elementList = ie.document.frames(myFrame).document.getElementsByTagName("span")
至于在点心
行的错误,你可以永远只是它定义为一个对象
或变
,这应该仍然工作,因为由的getElementsByTagName
应该还是有效的。
As far as the error on the Dim
line, you can always just define this as an Object
or Variant
and this should still work, since the type being returned by getElementsByTagName
should still be valid.
在回答您的更新,点击一个按钮,我使用:
Responding to your update, to click a button, I use:
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
与code混合,我就会把它一起像这样(未经):
Mixing with your code, I would put it together like this (untested):
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
这篇关于使用VBA自动化IE浏览器 - 点击链接的Javascript(无锚标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!