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 –