如何获得谷歌搜索下拉框关键字?
出海品牌数字营销者们在做关键字研究时需要用许多工具,其中一个重要的数据源便是谷歌搜索的相关词。而谷歌检索词自动完成,即搜索下拉框,是一个高质量的相关词数据源。那么如何自制工具批量获取该数据呢?马老师本篇将给出解决方案。

我们将通过Google Sheets来制作工具,如果你不想往下再读了,可以直接通过这个链接创建一个副本。
https://docs.google.com/spreadsheets/d/1IVW6Cf0PCxMOWTCU71_uJuJIxxGZ7KhSI8nZvRNjUyE/edit?usp=sharing

使用方法很简单:
在A列输入你要查询的检索词
选中你要查询的检索词
在菜单中点击Autocomplete Suggestions >Print Suggestions for Range
记得跑的时候要用你的谷歌账号授权并且对unsafe的脚本继续推进。
接下来讲如何自己做一个工具。
新建一个Google Sheet,自己在第一行添加一个表头。
在Extensions中打开Apps Script。
把下面代码复制到Code.gs中并保存。
关闭后刷新Google Sheet。完成。
代码如下,还不到一百行:
function getGoogleAutocompleteSuggestions(keyword) {try {// Construct the URL for the API requestconst apiUrl = `https://www.google.com/complete/search?q=${encodeURIComponent(keyword)}&cp=11&client=gws-wiz&xssi=t&gs_pcrt=undefined&hl=en&authuser=0`;// Make the HTTP GET requestconst response = UrlFetchApp.fetch(apiUrl);let content = response.getContentText();// Clean up the response to remove invalid JSON prefix ")]}'\n"content = content.replace(/^\)\]\}'/, "").trim();// Parse the cleaned content into a JSON objectconst json = JSON.parse(content);// Extract the suggestionsconst suggestions = json[0].map(item => {// Decode unicode characters and remove HTML tagsreturn item[0].replace(/\\u([0-9a-fA-F]{4})/g, (_, code) => String.fromCharCode(parseInt(code, 16))).replace(/<\/?[^>]+(>|$)/g, ""); // Strip HTML tags});return suggestions;} catch (error) {console.error("Error fetching or processing autocomplete suggestions:", error);return [];}}function printSuggestion(keywordCell, startCell) {// Get the active sheetvar sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();// Get the keyword from the input cellvar keyword = sheet.getRange(keywordCell).getValue();// Call the getGoogleAutocompleteSuggestions function to fetch suggestionsvar suggestions = getGoogleAutocompleteSuggestions(keyword);// If suggestions are found, print them horizontally starting from the specified cellif (suggestions.length > 0) {var range = sheet.getRange(startCell).offset(0, 0, 1, suggestions.length);range.setValues([suggestions]); // Set the suggestions in a single row} else {Logger.log("No suggestions found.");}}// Function to print suggestions for each keyword in the selected rangefunction printSuggestionsForRange() {var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();// Get the currently selected range (vertical range of keywords)var selection = sheet.getSelection();var range = selection.getActiveRange();var keywords = range.getValues(); // This returns a 2D array// Get the first cell to the right of the selected range (ensure it is within bounds)var firstRow = range.getRow(); // The first row of the selectionvar firstColumn = range.getColumn(); // The first column of the selectionvar lastRow = range.getLastRow(); // The last row of the selection// Get the next column to the right of the selected rangevar nextColumn = firstColumn + 1;var numColumns = sheet.getMaxColumns();if (nextColumn > numColumns) {// If out of bounds, alert the userLogger.log("Error: The selection is at the edge of the sheet. There is no next column.");return;}// For each keyword in the range, call the printSuggestion functionfor (var i = 0; i < keywords.length; i++) {var keyword = keywords[i][0]; // Get the keyword value from the rowvar currentOutputCell = sheet.getRange(firstRow + i, nextColumn); // Output starts in the next column in the same row// Call printSuggestion to print suggestions horizontallyprintSuggestion(keyword, currentOutputCell.getA1Notation());}}// Modified printSuggestion to work with cell rangefunction printSuggestion(keyword, startCell) {var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();var suggestions = getGoogleAutocompleteSuggestions(keyword); // Fetch suggestionsif (suggestions.length > 0) {// Create a range starting from the given startCell and set the valuesvar range = sheet.getRange(startCell).offset(0, 0, 1, suggestions.length);range.setValues([suggestions]); // Print suggestions in a horizontal row} else {Logger.log("No suggestions found for: " + keyword);}}// Function to add a custom menu to the sheetfunction onOpen() {var ui = SpreadsheetApp.getUi();ui.createMenu('Autocomplete Suggestions').addItem('Print Suggestions for Range', 'menuPrintSuggestionsForRange').addToUi();}// Menu function to call printSuggestionsForRangefunction menuPrintSuggestionsForRange() {printSuggestionsForRange();}
以上就是工具的整个制作过程。如果你有疑问请公众号后台私信。

入群联系|加微信89931668
免费DeepSeek教程与学习资料

                                
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                
                            
                                    
                                    
                                    
                                    
            
  
请先 登录后发表评论 ~