在Excel中给出一串字符串,是否有一种简单的方法可以返回Google搜索中每个字符串的结果数量?我正在寻找一种方法将Excel中的文本数据列表转换为Google搜索结果。Excel的Google搜索结果数量
4
A
回答
5
From here思想(但修改):
Public Sub ExcelGoogleSearch()
Dim searchWords As String
With Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) <> ""
searchWords = .Range("A" & RowCount).Value
' Get keywords and validate by adding + for spaces between
searchWords = Replace$(searchWords, " ", "+")
' Obtain the source code for the Google-searchterm webpage
search_url = "http://www.google.com/search?hl=en&q=" & searchWords & "&meta="""
Set search_http = CreateObject("MSXML2.XMLHTTP")
search_http.Open "GET", search_url, False
search_http.send
results_var = search_http.responsetext
Set search_http = Nothing
' Find the number of results and post to sheet
pos_1 = InStr(1, results_var, "resultStats>", vbTextCompare)
pos_2 = InStr(3 + pos_1, results_var, ">", vbTextCompare)
pos_3 = InStr(pos_2, results_var, "<nobr>", vbTextCompare)
NumberofResults = Mid(results_var, 1 + pos_2, (-1 + pos_3 - pos_2))
Range("B" & RowCount) = NumberofResults
RowCount = RowCount + 1
Loop
End With
End Sub
HTH
+0
谢谢。这似乎工作,除了我想用它在西里尔语中的一些文本,并没有正确的工作,但我认为我可以弄明白。 – user584974 2011-01-22 03:15:22
0
上述代码可以创造奇迹。另一方面,如果搜索到的字符串带来0个结果,则会崩溃。一个简单的例子解决了这个问题。只是fyi。
Public Sub ExcelGoogleSearch()
Dim searchWords As String
With Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) <> ""
searchWords = .Range("A" & RowCount).Value
' Get keywords and validate by adding + for spaces between
searchWords = Replace$(searchWords, " ", "+")
' Obtain the source code for the Google-searchterm webpage
search_url = "http://www.google.com/search?hl=en&q=""" & searchWords & """&meta="""
Set search_http = CreateObject("MSXML2.XMLHTTP")
search_http.Open "GET", search_url, False
search_http.send
results_var = search_http.responsetext
Set search_http = Nothing
' Find the number of results and post to sheet
pos_1 = InStr(1, results_var, "resultStats>", vbTextCompare)
If pos_1 = 0 Then
NumberofResults = 0
Else
pos_2 = InStr(3 + pos_1, results_var, ">", vbTextCompare)
pos_3 = InStr(pos_2, results_var, "<nobr>", vbTextCompare)
NumberofResults = Mid(results_var, 1 + pos_2, (-1 + pos_3 - pos_2))
End If
Range("B" & RowCount) = NumberofResults
RowCount = RowCount + 1
Loop
End With
End Sub
1
此代码需要更新,因为Google稍微更改了其源代码。这是一个2013年11月11日起对所有需要它的代码生效的代码(稍做其他修改,宏忽略第一行,因此您可以将列标题和搜索结果转换为值,以便它们可以操作/排序与Excel
Public Sub ExcelGoogleSearch()
Dim searchWords As String
With Sheets("Sheet1")
RowCount = 2
Do While .Range("A" & RowCount) <> ""
searchWords = .Range("A" & RowCount).Value
' Get keywords and validate by adding + for spaces between
searchWords = Replace$(searchWords, " ", "+")
' Obtain the source code for the Google-searchterm webpage
search_url = "https://www.google.com/search?hl=en&q=" & searchWords & "&meta="""
Set search_http = CreateObject("MSXML2.XMLHTTP")
search_http.Open "GET", search_url, False
search_http.send
results_var = search_http.responsetext
Set search_http = Nothing
' Find the number of results and post to sheet
pos_1 = InStr(1, results_var, "div id=" & Chr(34) & "resultStats", vbTextCompare) + 21
If pos_1 = 21 Then
NumberofResults = 0
Else
pos_2 = InStr(pos_1, results_var, "result", vbTextCompare) - 1
NumberofResults = Val(Replace(Replace(Mid(results_var, pos_1, pos_2 - pos_1), ",", ""), "About", ""))
End If
Range("B" & RowCount) = NumberofResults
RowCount = RowCount + 1
Loop
End With
End Sub
相关问题
- 1. 来自Excel的搜索结果数量
- 2. Google Maps API Places搜索获取搜索结果数量
- 3. 检索Google API搜索结果的数量
- 4. 如何在Google搜索结果页中提取搜索结果的总量
- 5. Excel VBA中的计数搜索结果
- 6. 在PHP中搜索Google搜索结果
- 7. google api搜索结果
- 8. 访问Google搜索结果
- 9. Google搜索结果限制
- 10. Google地方搜索结果
- 11. 提取Google搜索结果
- 12. 在Google中搜索结果
- 13. 优化Google搜索结果
- 14. Google搜索结果页面
- 15. 如何提取Google自定义搜索API中的搜索结果数量?
- 16. 仅通过Python返回Google搜索结果的数量
- 17. 记录来自Google的搜索结果数量
- 18. Google Ajax搜索结果与“普通”Google搜索结果有什么不同?
- 19. Google应用索引ios搜索结果
- 20. 如何在Excel VBA中使用Google的搜索结果?
- 21. Google Youtube上的歌曲搜索结果
- 22. 以Google搜索的结果为例
- 23. Google的搜索结果是否抵消了Bing的搜索结果?
- 24. 如何搜索Google搜索结果中的网址?
- 25. HTML来搜索Excel和显示结果
- 26. 过滤Google网站搜索结果
- 27. 提取Google搜索结果重定向
- 28. 在Google搜索结果时绕过KeyError
- 29. 使用ImportXML导入Google搜索结果
- 30. 解析器Google搜索结果
你可以看看尼尔斯·博冠的(免费)SEOTools Excel插件:。http://nielsbosma.se/projects/seotools/它有大量的用于Web类似的功能metrics。 – Govert 2012-03-05 19:39:43