如何在excel中使用VBA查找并点击href链接。
更多信息
我尝试了许多方法,但是失败了。我是VBA excel网络抓取中的新手,对我来说并不容易。
有人可以告诉我.getelementbyclass无法获得哪些类型的类。
在excel中使用VBA。
该网页的
html代码如下:
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="newErrorPageTemplate.css">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This site isn’t secure</title>
<script src="invalidcert.js" language="javascript" type="text/javascript">
</script>
<script src="errorPageStrings.js" language="javascript" type="text/javascript">
</script>
<script src="httpErrorPagesScripts.js" language="javascript" type="text/javascript">
</script>
</head>
<body onLoad="BodyLoad(); initMoreInfo('infoBlockID');">
<div id="contentContainer" class="mainContent">
<div id="invalidcert_mainTitle" class="title" style="color: #a90000;">This site is not secure</div>
<div id="invalidcert_subError" class="BodyTextBlockStyle">
This might mean that someone’s trying to fool you or steal any info you send to the server. You should close this site immediately.<br><br>
</div>
<div class="BaseTextBlockStyle"><a href="javascript:close();"><img class="shieldImage" alt="Recommended icon" src="shieldcheck.ico" width="20px" height="20px"><id id="invalidcert_closeTab">Close this tab</id></a><br></div>
<div id="moreInformationAlign" align="left" aria-labelledby="moreInformation">
<table>
<tr>
<td valign="top" aria-labelledby="infoBlockIDImage">
<a href="#" onclick="javascript:expandCollapse('infoBlockID', true); return false;"><img src="down.png" id="infoBlockIDImage" border="0" class="actionIcon" alt="More information"></a>
</td>
<td valign="top">
<span id="moreInfoContainer"></span>
<noscript><id id="moreInformation">More information</id></noscript>
</td>
</tr>
</table>
<div id="infoBlockID" class="infoBlock" style="display: none">
<br/>
<b><span id="certReason" style="margin-left:20px"></span></b>
<p id="ErrorCode" style="margin-left:20px"></p>
<p class="BaseTextBlockStyle" id="override" style="margin-left:20px"><a href="#" id="overridelink"><img class="shieldImage" alt="Not recommended icon" src="shieldcritical.ico" width="20px" height="20px">Go on to the webpage (not recommended)</a></p>
</div>
</div>
</div>
</body>
</html>
我的vba代码是
Sub reboot_router_01()
Dim ie As InternetExplorer
Dim webpage As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate ("http://192.168.1.1/")
Do While ie.Busy = True
Loop
Set webpage = ie.document
Dim aTag As Object
For Each aTag In ie.document.getElementsByTagName("a")
If aTag.innerText = "More information" Then
MsgBox (ie.document.getElementsByTagName("a"))
aTag.Click
Exit For
End If
Next aTag
End Sub
但是它不起作用