2016-11-28 62 views
0

我想知道整個網站是否存在某個關鍵字。如何搜索整個網站的關鍵字

我該怎麼辦?

快速谷歌搜索建議這樣

「谷歌搜索101)

..只是鍵入搜索字詞,後跟site:www.website.com

但我不確定如何測試它是否返回正面或負面。

任何人都可以幫忙嗎?

+0

也許你的谷歌太快了? http://www.mrexcel.com/forum/excel-questions/277591-vbulletin-macro-search-webpage-text-string.html –

+0

@TimWilkinson沒有先生我知道這個解決方案,不同的是我想搜索整個網站,而不是一個單一的網頁。 – newguy

回答

1

試試這個,它基本上是檢查是否通過搜索網站上的關鍵字或短語有任何谷歌的搜索結果:

Sub Check_Website() 

Dim ie As Object 
Dim str As String, web As String, URL As String 
Dim iResults As Integer 

'Create IE object 
Set ie = CreateObject("InternetExplorer.Application") 

'Set string to search for 
str = "hello" 
str = Replace(str, " ", "+") 

'Set website to search in 
web = "www.google.com" 

'Create full URL 
URL = "https://www.google.co.uk/search?q=" & str & "+site%3A" & web 

'Navigate to URL 
With ie 
    .Visible = False 
    .Navigate URL 
    Do While .ReadyState <> 4: DoEvents: Loop 
End With 

'Count results on first page 
iResults = ie.Document.getelementsbyclassname("g").Length 

'Message box dependent on results 
If iResults = 0 Then 
    MsgBox "No matches were found." 
Else 
    MsgBox "Matches found." 
End If 

ie.Quit 
Set ie = Nothing 

End Sub 

谷歌使用的「G」之類的名稱有搜索結果意味着有在特定搜索結果頁面的「g」類中最多有10個項目,如果沒有顯示任何結果,則不存在「g」類別,這意味着沒有要計算的項目。

+0

非常感謝:) – newguy

2

像這樣的事情也

Function FIND_IN_PAGE(strURL As String, strSearch As String) 

Dim pos As Long 
Dim ie As SHDocVw.InternetExplorer 
Dim doc As MSHTML.HTMLDocument 

Set ie = New SHDocVw.InternetExplorer 

ie.Visible = 1 
ie.navigate strURL 

Do Until ie.readyState = READYSTATE_COMPLETE And ie.Busy = False 
    DoEvents 
Loop 

Set doc = ie.document.DocumentElement 

pos = InStr(1, doc.innerText, strSearch) 

FIND_IN_PAGE = pos 

ie.Quit 

Set ie = Nothing 
Set doc = Nothing 

End Function 

調用像這樣

FIND_IN_PAGE("http://stackoverflow.com/questions/40848321/how-to-search-for-a-keyword-in-entire-website","entire")

相關問題