2016-03-03 66 views
0

我很熟悉在Excel上製作宏,但是這個讓我難住。使用Excel VBA的Javascript(Google Adwords)

我有一個項目列表(> 250),我需要列出相應的關鍵字。對於這個應用程序,我發現Google Adwords關鍵字生成器工具是最好的資源。

,我使用這個鏈接是: - https://adwords.google.com/ko/KeywordPlanner/Home?__c=6147994389&__u=6746703189&authuser=0&__o=cues#start

Screenshot

在這裏我要補充基本的關鍵字,並下載結果以CSV格式。不過,我無法通過excel自動執行此操作。我的主要問題是,當我通過VBA腳本輸入搜索關鍵字時,文本框內的文本會發生變化,但一旦單擊「獲取創意」按鈕,系統將忽略新值並搜索舊值。

其次,我似乎無法點擊「下載」按鈕。

我的代碼如下。

'Menu > Tools > References   (To add required libraries) 
'Enable Microsoft Internet controls 
'Enable Microsoft HTML Object Library 


Sub Key_word() 



i = 2 


'Sheets("Keywords").Activate 

i = i + 1 


keyword_main = Cells(i, 2).Value 



Dim login As Object 
Dim Input_box As Object 
Dim Input_box1 As Object 
Dim Get_ideas As Object 
Dim Dowload_all As Object 
Dim Entry As Object 
Dim table_res As Object 
Dim image_wt As Object 
Dim wsTarget As Worksheet 

'Set wsTarget = ActiveWorkbook.Worksheets("raw") 


Set ie = CreateObject("InternetExplorer.Application") 

ie.Visible = 1 'false 

ie.navigate "https://adwords.google.com/ko/KeywordPlanner/Home?__c=6147994389&__u=6746703189&authuser=0&__o=cues#search" 

Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop 



''Set login = ie.document.getElementsByClassName("maia-button") 
'Set login = ie.document.getElementById("splash-content") 
'If (login <> "Nothing") Then 
'login.Focus 
'login.Click 
''login 
'End If 


Set Entry = ie.document.getElementById("gwt-debug-splash-panel-resume-anchor") 

If (Entry <> "Nothing") Then 
Entry.Focus 
Entry.Click 
End If 

rep = 6 

While (rep = 6) 

Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop 

'text 
'"gwt-debug-keywords-text-area" 
Set Input_box = ie.document.getElementById("gwt-debug-keywords-text-area") 

Set Input_box1 = ie.document.getElementById("gwt-debug-category-input") 

'Set Input_box = ie.document.getElementById("gwt-debug-search-button") 

'Object HTMLDivElement 

'Input_box.Activate 

Input_box.Value = "LM339" 
Input_box1.Value = "LM339" 
'Input_box.Enter 


'MsgBox ("1") 

'Application.Wait (Now + TimeValue("00:00:20")) 
' 
'Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop 
'get ideas 
'"gwt-debug-search-button-content" 
Set Get_ideas = ie.document.getElementById("gwt-debug-search-button") 
If (Get_ideas <> "Nothing") Then 
Get_ideas.Focus 
Get_ideas.Click 
End If 
' 
'Application.Wait (Now + TimeValue("00:01:20")) 
Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop 

'download button 
'"gwt-debug-search-download-button" 

''<div tabindex="0" class="ninja-button goog-inline-block goog-button goog-button-base" role="button" aria-labelledby="gwt-uid-4764" aria-haspopup="true"><input type="text" tabindex="-1" role="presentation" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;"><div class="goog-button-base-outer-box goog-inline-block"><div class="goog-button-base-inner-box goog-inline-block"><div class="goog-button-base-pos"><div class="goog-button-base-top-shadow">&nbsp;</div><div class="goog-button-base-content"><span class="aw-toolbelt-downloadButton sptd-b sptd-c">Download</span></div></div></div></div></div> 
'Set Dowload_all = ie.document.getElementsByClassName("ninja-button goog-inline-block goog-button goog-button-base") 
'If (Dowload_all <> "Nothing") Then 
'Dowload_all.Focus 
'Dowload_all.Click 
'End If 

'Application.Wait (Now + TimeValue("00:00:20")) 


'ie.Quit 

'Set ie = Nothing 

rep = MsgBox("repeat", vbYesNo) 

'MsgBox (rep) 

Wend 

'End Function 
End Sub 

' 

我認爲我沒有針對正確的ID,但經過數小時的試錯和網絡搜索,我沒有結果。

在此先感謝 Sujoy。

回答

0

最後它與iMacros合作。我使用excel宏在iMacros中生成2000多行代碼,然後在iMacros中運行代碼以獲得正確的結果。

乾杯, Sujoy。

注意: - iMacros在Firefox中效果最佳。