Vba 如何在整个网站中搜索关键字
我想知道某个关键字是否存在于整个网站中 我怎么做 快速的谷歌搜索建议这样做 “谷歌搜索101) …只需键入搜索词,然后键入网址:www.website.com 但我不知道如何测试它是否返回正或负Vba 如何在整个网站中搜索关键字,vba,excel,web-scraping,Vba,Excel,Web Scraping,我想知道某个关键字是否存在于整个网站中 我怎么做 快速的谷歌搜索建议这样做 “谷歌搜索101) …只需键入搜索词,然后键入网址:www.website.com 但我不知道如何测试它是否返回正或负 有人能帮忙吗?试试这个,它基本上是通过在网站上搜索关键字或短语来检查是否有谷歌搜索结果: Sub Check_Website() Dim ie As Object Dim str As String, web As String, URL As String Dim iResults As Integ
有人能帮忙吗?试试这个,它基本上是通过在网站上搜索关键字或短语来检查是否有谷歌搜索结果:
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
Sub-Check_网站()
模糊的物体
Dim str作为字符串,web作为字符串,URL作为字符串
Dim iResults为整数
'创建IE对象
设置ie=CreateObject(“InternetExplorer.Application”)
'设置要搜索的字符串
str=“你好”
str=替换(str,“,”+”)
'设置要在中搜索的网站
web=“www.google.com”
'创建完整URL
URL=”https://www.google.co.uk/search?q=&str&“+site%3A”&web
'导航到URL
与ie
.Visible=False
.浏览网址
执行While.ReadyState 4:DoEvents:Loop
以
'在第一页上计算结果
iResults=ie.Document.getElementsByCassName(“g”).Length
'消息框取决于结果
如果iResults=0,则
MsgBox“未找到匹配项。”
其他的
MsgBox“找到匹配项。”
如果结束
即退出
设置ie=无
端接头
谷歌在搜索结果中使用了类名“g”,这意味着对于特定的搜索结果页面,“g”类中最多有10个项目,如果没有显示任何结果,那么就没有“g”“类,这意味着没有要统计的项目。试试这个,它基本上通过在网站上搜索关键字或短语来检查是否有谷歌搜索结果:
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
Sub-Check_网站()
模糊的物体
Dim str作为字符串,web作为字符串,URL作为字符串
Dim iResults为整数
'创建IE对象
设置ie=CreateObject(“InternetExplorer.Application”)
'设置要搜索的字符串
str=“你好”
str=替换(str,“,”+”)
'设置要在中搜索的网站
web=“www.google.com”
'创建完整URL
URL=”https://www.google.co.uk/search?q=&str&“+site%3A”&web
'导航到URL
与ie
.Visible=False
.浏览网址
执行While.ReadyState 4:DoEvents:Loop
以
'在第一页上计算结果
iResults=ie.Document.getElementsByCassName(“g”).Length
'消息框取决于结果
如果iResults=0,则
MsgBox“未找到匹配项。”
其他的
MsgBox“找到匹配项。”
如果结束
即退出
设置ie=无
端接头
谷歌在搜索结果中使用了类名“g”,这意味着对于特定的搜索结果页面,“g”类中最多有10个项目,如果没有显示任何结果,那么就没有“g”类,这意味着没有要统计的项目。类似的内容
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_页面(“http://stackoverflow.com/questions/40848321/how-to-search-for-a-keyword-in-entire-website“,”整个“
类似的内容
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_页面(“http://stackoverflow.com/questions/40848321/how-to-search-for-a-keyword-in-entire-website“,”整个“
也许你的谷歌搜索速度太快了@TimWilkinson不,先生,我知道这个解决方案不同的是我想搜索整个网站,而不是一个网页。也许你的谷歌搜索太快了@TimWilkinson不,先生,我知道这个解决方案不同的是我想搜索整个网站,而不是一个网页。