如何在整个网站中搜索关键字



我想知道整个网站中是否存在某个关键字。

我该怎么做?

快速谷歌搜索使用这种方式

;谷歌搜索101)

..只需输入您的搜索字词,然后是网站:www.website.com

但我不确定如何测试它是返回正还是负。

任何人可以帮忙吗?

类似的东西也

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")

尝试一下,它基本上检查了是否有Google搜索结果,通过在网站上搜索关键字或短语:

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

Google使用" G"的类名称进行搜索结果,这意味着特定搜索结果页面中最多将有10个项目,如果没有显示结果,则没有" G"类这意味着无需计算项目。

最新更新