Как заполнить результаты поиска Google на листе в Excel?
В некоторых случаях вам может потребоваться выполнить поиск по важным ключевым словам в Google и сохранить запись о лучших результатах поиска на листе, который включает заголовок и гиперссылку статьи. В этой статье представлен метод VBA, который помогает заполнить результаты поиска Google на листе на основе заданных ключевых слов в ячейках.
Заполните результаты поиска Google на листе с кодом VBA
Заполните результаты поиска Google на листе с кодом VBA
Предположим, что вам нужны ключевые слова для поиска в списке в столбце A, как показано на скриншоте ниже, сделайте следующее, чтобы заполнить результаты поиска Google по этим ключевым словам в соответствующие столбцы с кодом VBA.
1. нажмите другой + F11 , чтобы открыть Microsoft Visual Basic для приложений окно.
2. в Microsoft Visual Basic для приложений окно, пожалуйста, нажмите Вставить > Модули. Затем скопируйте и вставьте код VBA в окно кода.
Код VBA: заполнить результаты поиска Google на листе
Sub xmlHttp()
'Updated by Extendoffice 2018/1/30
Dim xRg As Range
Dim url As String
Dim xRtnStr As String
Dim I As Long, xLastRow As Long
Dim xmlHttp As Object, xHtml As Object, xHtmlLink As Object
On Error Resume Next
Set xRg = Application.InputBox("Please select the keywords you will search in Google:", "KuTools for Excel", Selection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
xLastRow = xRg.Rows.Count
Set xRg = xRg(1)
For I = 0 To xLastRow - 1
url = "https://www.google.co.in/search?q=" & xRg.Offset(I) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
Set xmlHttp = CreateObject("MSXML2.serverXMLHTTP")
xmlHttp.Open "GET", url, False
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
xmlHttp.send
Set xHtml = CreateObject("htmlfile")
xHtml.body.innerHTML = xmlHttp.ResponseText
Set xHtmlLink = xHtml.getelementbyid("rso").getelementsbytagname("H3")(0).getelementsbytagname("a")(0)
xRtnStr = Replace(xHtmlLink.innerHTML, "<EM>", "")
xRtnStr = Replace(xRtnStr, "</EM>", "")
xRg.Offset(I, 1).Value = xRtnStr
xRg.Offset(I, 2).Value = xHtmlLink.href
Next
Application.ScreenUpdating = True
End Sub
3. Press the F5 key to run the code. In the popping up Kutools for Excel dialog box, please select the cells containing keywords you will search, and then click the OK button. See screenshot:

Then all search results including titles and links are populated into corresponding column cells based on keywords. See screenshot:

Related articles:
- How to populate a combo box with specified data on Workbook open?
- How to auto populate other cells when selecting values in Excel drop down list?
- How to auto populate other cells when selecting values in Excel drop down list?
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
- Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
- Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
- Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
- Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
- Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
- Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
- Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
- Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
- More than 300 powerful features. Supports Office / Excel 2007-2021 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Sort comments by
#28233
This comment was minimized by the moderator on the site
Report
0
0
#28234
This comment was minimized by the moderator on the site
0
0
#29011
This comment was minimized by the moderator on the site
0
0
#30491
This comment was minimized by the moderator on the site
0
0
#30492
This comment was minimized by the moderator on the site
Report
0
0
#30493
This comment was minimized by the moderator on the site
0
0
There are no comments posted here yet