如何使用vba excel在网页上点击超链接?
我是新的Excel VBA编程。 我一直在尝试使用excel vba从近3天的网页上点击一个超链接。 请帮我一下 由于我是新手,所以我可能犯了很多错误。 请原谅我。
scheme是:一个特定的网页有一个第一列作为图标的表格,第二列是一个超链接和一些更多的列有一些关于超链接的描述。
现在,我想单击第一行(第二列)中的超链接。 当我们将鼠标hover在同一行(第一列)中的图标上时,会显示相同的超链接。
这个网页是dynamic的,因此表格不断变化。 实际上,表格是inputsearch条件的结果。
我已经写了很多代码从三天。 这是最新的不工作:
'获取行的元素ID
With elementid = ieApp.document.all.Item("abcrow1") 'checking for details with tagname as "a" Set tagname = ieApp.document.getElementByTagName("a") For Each tag In tagname 'Get value of the href hrefvalue = tag.href.value If Not IsNull(hrefvalue) Then If hrefvalue <> "javascript:void(0);" Then 'this href is usedto describe the icon hrefvalue = ieApp.document.href.value hrefvalue = "https://www.secur.com" & hrefvalue ieApp.Navigate hrefvalue Exit For End If End IF Next tag End With
HTML脚本如下所示:
<tr id = "abcrow1" class="e1"> <td class = "icon"></td> <td><ul class="xyz" id="link"> <li><a href = "javascript:void(0);"><img src="/nnn.gif" border = 0 alt = "info" </a> <ul> <li><a onclick ="return cursorWait(this);" href = "/xyz/lmo">DetailOfRow1</a></li></ul></td> <td style = "text-align:left"><aonclick="return cursorWait(this);" href = "/xyz/lmo">DetailOfRow1</a></td></tr>
请帮我一下 谢谢。
这是否工作? 如果不是,hrefvalue_1和hrefvalue_2会评估什么?
Set Tagname = ieApp.document.getElementsByTagName("a") For Each Tag In Tagname If InStr(1, Tag.innertext, "DetailOfRow1", vbTextCompare) > 0 Then hrefvalue_1 = Tag ' tag may contain "about:", if so remove it hrefvalue_2 = Replace(Tag, "about:", "", 1, -1, vbTextCompare) hrefvalue_3 = "https://www.secur.com" & hrefvalue_2 ieApp.Navigate hrefvalue Exit For End If Next Tag
如果没有访问url,有点难以确定,但沿着这些线路的东西应该工作…
With elementid = ieApp.document.all.Item("abcrow1") 'checking for details with tagname as "a" Set tagname = ieApp.document.getElementByTagName("a") For Each tag In tagname 'Get value of the href If InStr(1, tag.getAttribute("href"), "javascript:void(0);", vbTextCompare) = 0 Then hrefvalue = tag hrefvalue = "https://www.secur.com" & hrefvalue ieApp.Navigate hrefvalue Exit For End If Next tag End With