2016-03-03 73 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中效果最佳。