HACK#84AdWordsGoogleAdWordsGoogleGoogleAdWords108GoogleAdWordsCTRCTRGoogleAdWordsTrafficEstimatorAdWordshack7-71.02.0AdWordsTrafficEstimatorGoogleAdWordshackestimator355AdWordsAdWordsAdWordshackGoogleAdWordsAdWordsTrafficGenerator::SSLeayAdWordsGoogleAdWords::TableContentParserText::CSVCSVPerlPerlGoogle[Hack#92]WindowsCrypt::SSLeayActiveStateWindowsActivePerlPPMStatusoftheActiveStatePPMRepositories!/usr/bin/perl-w#adwords_worth.pl#AutomategleaningGoogleAdWordsestimatedcost-per-clicks(CPCs)#Usage:perladwords_worth.plkeyword1keyword2[..]#perladwords_worth.plkeywords.txtusestrict;use::TableContentParser;useText::CSV;=head1NAMEadwords_worth-ReturnsestimatedGoogleAdWordscost-per-clicks(CPCs)ofprovidedkeywordsincomma-separated(CSV)format.=cut#Fillupkeywords.my$keyword_string;if(not@ARGV){#Youpipedinafilelocal$/=undef;$keyword_string=STDIN;}else{#Keywordsarespecifiedoncommandline$keyword_string=join(\n,@ARGV);}361dieNokeywordsspecified!unless$keyword_string=~/\w+/;=head1SYNOPSISadwords_worth.plkeyword1[..]adwords_worth.plkeywords.txt=cut#Setup=(autocheck=1);#Getinitialpage.printSTDERRFetchingtheAdwordsinitialpage...;$agent-get(');$agent-form_number(3);$agent-click('start');printSTDERRok\n;printSTDERRVisitingtheLanguageandTargetingpage...;#OnLanguageandTargetingpage.#Defaultsareokayfornow.$agent-click('save');printSTDERRok\n;#Oncountryselector.#RightnowdefaultvalueisAllCountries.printSTDERRVisitingtheCountryselector...;$agent-click('save');printSTDERRok\n;#OnCreateAdpage.#Fillinplaceholdervalues,sinceitdoesn'tmatter.#CAVEAT:Allcreativelinesmustbespelledcorrectly.#See:Adwordseditorialguidelines.printSTDERRCreatingaplaceholderad...;$agent-current_form-value('adGroupName','groupname');$agent-current_form-value('creative.line1','Spelling');$agent-current_form-value('creative.line2','Spelling');$agent-current_form-value('creative.line3','Spelling');$agent-current_form-value('creative.visibleUrl','a.com');$agent-current_form-value('creative.destUrl','a.com');$agent-click('save');printSTDERRok\n;#OnKeywordspage.printSTDERRPlugginginyourkeywords...;$agent-current_form-value('keywords',$keyword_string);$agent-click('save');printSTDERRok\n;362#OnPriceTablePage,butnovaluesareinthetable.printSTDERRRecalculatingkeywordvalues...;$agent-click('recalculate');printSTDERRok\n;#NowonPriceTablepage,andthetablenowhasvalues.printSTDERRGleaningkeywordvaluesandbuildingyouaCSV...\n\n;my$p=HTML::TableContentParser-new();my$tables=$p-parse($agent-content());#Tablewiththevaluesishasitsclassattributesettoreport.my@report_tables=grep{exists$_-{class}and$_-{class}eq'report'}@$tables;#AssumingthatGoogleonhasonreporttableperpage.my$table=$report_tables[0];#MakeCSVobjectouthereinsteadofhavingloopmakeXofthem.my$csv=Text::CSV-new();#Gettherowsofcellsoutof$table'sconvolutedstructure.#TODOnamingofvariableshereisodd,butcheckoutDumper(\@row_cell_objs).my@row_cell_objs=grep{$_-{cells}}@{$table-{rows}};my@data_cells=map{$_-{cells}}@row_cell_objs;foreachmy$row($table-{headers},@data_cells){#Justbeingsafeherewithreferences.if(ref$roweq'ARRAY'){#Eliminatetitlecellandcellsinrightmostcolumn.#Theycontainonlylinks.my@table_cells=grep{notexists$_-{class}or$_-{class}ne'rightcolumn'}@$row;my@data=map{$_-{data}}@table_cells;foreach(@data){#RemoveHTMLtagsandsurroundingwhitespace.s/[^]*//g;s/^\s+//;s/\s+$//;s/\<//g;#Numberofclickscontainscommas,butwedon'twantthose.tr/,//d;}#MakeaCSVlineandprintit.if($csv-combine(@data)){print$csv-string,\n;}else{my$err=$csv-error_input;363printcombine()failedonargument:,$err,\n;}}else{printRowisnotanarrayofcells!\n;}}printSTDERRDone.\n;=head1AUTHORLelandJohnsoneasyasy2k@gmail.com=cuthackhack$perladwords_worth.pladwordanotheradwordonemore$perladwords_worth.pladwords.txtCSV.csv$perladwords_worth.pladwords.txtadwords.csvGoogleAdWords$perladwords_worth.plGeorgeBushJohnKerryRalphNaderSomeoneElseFetchingtheAdwordsinitialpage...okVisitingtheLanguageandTargetingpage...ok364VisitingtheCountryselector...okCreatingaplaceholderad...okPlugginginyourkeywords...okRecalculatingkeywordvalues...okGleaningkeywordvaluesandbuildingyouaCSV...Keyword,Clicks/Day,AverageCost-Per-Click,Cost/Day,AveragePosition[?]GeorgeBush,910.0,$0.21,$189.88,1.3JohnKerry,810.0,$0.18,$138.36,1.4RalphNader,0.1,$0.00,$0.00,-SomeoneElse,33.0,$0.09,$2.67,1.2Overall,1771.0,$0.19,$