我一直在做了很多关于这个研究,但我似乎无法弄清楚到底如何解决我的问题。在列N:N,我有上百个,我通过和开放要循环链接。一旦代码打开它们,我有了的话/我想要的代码来引用,通过每一个人的链接进行搜索时短语的动态列表另一个工作表。如果代码没有找到在页面什么,那关闭窗口并移动到下一个环节。如果它找到匹配(不必区分大小写),然后将其复制的所有单词/在对应的O短语:O单元各由一个“;”分隔。
根据我的研究,我有此代码段,这将打开链接:
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
Dim x As Integer
Dim links As Hyperlinks
Set links = ActiveSheet.Hyperlinks
For x = 1 To links.Count
ie.navigate links.Item(x).Address, Nothing, "_blank"
Next
不过,我似乎无法找到任何帮助我这个代码的最后一部分。我相当熟悉VBA,但是这是我的技能组合。
谢谢先进!
对于网页搜索的关键字或文字,你可以参考下面的代码示例。
Sub scraper()
Dim site As String
Dim lastRow As Long
Dim ie
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate site
'idle while ie is busy
Do
Loop Until ie.readystate = 3
Do
Loop Until ie.readystate = 4
With ie.document
.getelementbyid("UserName").Value = uName
.getelementbyid("Password").Value = uPass
.forms(0).submit
End With
On Error GoTo error
Do
Loop Until ie.readystate = 3
Do
Loop Until ie.readystate = 4
For i = 2 To lastRow
site = Range("A" & i).Value
ie.navigate site
Do
Loop Until ie.readystate = 3
Do
Loop Until ie.readystate = 4
msg = ie.document.Body.innerhtml
If InStr(msg, "Text To Find") = 0 Then
ActiveSheet.Range("B" & i).Value = "Not Found"
Else
ActiveSheet.Range("B" & i).Value = "Found"
End If
jump:
Next i
Exit Sub
error:
ActiveSheet.Range("B" & i).Value = "Unknown Error!"
Resume jump
End Sub
这是示例代码,你可以尝试修改它按照自己的要求。
参考:
Search a web page for a particular text
对于副本从一个细胞粘贴值到另一个,您可以参考以下链接可以给你一个想法。