0
我想做一些奇特的事情来缓解我对普通网站的浏览,但问题是我真的不知道该怎么做,或者甚至可能与Excel一起使用。搜索特定文本的网页
我想要做的是为excel搜索给定页面上的文字,如“Overstock”。如果找到该单词,则返回给定单元格中“Full”或“Overstock”或相反的结果。
这样做的原因是,只需打开一个excel即可检查100多页,并为每个页面分别显示结果。
我想做一些奇特的事情来缓解我对普通网站的浏览,但问题是我真的不知道该怎么做,或者甚至可能与Excel一起使用。搜索特定文本的网页
我想要做的是为excel搜索给定页面上的文字,如“Overstock”。如果找到该单词,则返回给定单元格中“Full”或“Overstock”或相反的结果。
这样做的原因是,只需打开一个excel即可检查100多页,并为每个页面分别显示结果。
这应该做你想做的一些修改。
我有代码在那里登录到我使用的网站,但可能不需要你。
我已经从一个更大的宏切碎了这个,所以可能有一些在这里不需要的位。
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
谢谢。像魅力一样工作。 – user99776644
请参阅http://stackoverflow.com/questions/9758107 –