我正在尝试编写一些代码来在 excel 单元格中查找一个单词,搜索该单词,最重要的是,单击返回的链接。
我有搜索部分,但它是我正在努力的链接的点击。HMTL 提取物是 -
<span>
<div class="searchResult webResult ">
<div class="resultTitlePane">
<h3>
<a class="outbound" href="whatever" target ="" rel="nofollow" rev="lots of
text">..</a>
</h3>
</div>
我没有输入 href 和 rel 文本,但我只想能够单击返回的链接并继续访问该站点。请问有什么帮助吗?
这是我的代码 -
Sub test()
Dim ie As InternetExplorer
Dim RegEx As RegExp, RegMatch As MatchCollection
Dim MyStr As String
Dim pDisp As Object
Dim dtStartTime As Date
Set ie = New InternetExplorer
Set RegEx = New RegExp
Dim iedoc As Object
SearchEng = "http://easysearch.org.uk/search/?s="
LastRow = Range("A1").End(xlDown).Row
Do Until i = LastRow + 1
SearchMe = Range("A" & i)
ie.Navigate SearchEng & SearchMe
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
MyStr = ie.document.body.innerText
Set RegMatch = RegEx.Execute(MyStr)
If RegMatch.Count > 0 Then
ie.Navigate RegMatch(0)
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
ie.Visible = True
Set iedoc = ie.document
''NEED TO ADD SOMETHING HERE TO CLICK LINK''
End If
i = i + 1
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Loop
Set RegEx = Nothing
ie.Quit
Set ie = Nothing
End Sub