Google广告批量投放脚本
Posted chunfang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google广告批量投放脚本相关的知识,希望对你有一定的参考价值。
该脚本文件是一个转化文件,将编辑的Google投广告模板转化成Google批量投放广告的脚本文件,实现批量投放广告,节省投广时间。PS:要与相应的模板结合使用,投广告模板在本人博客的文件中,可以下载。
关于模板的注意事项:
1、模板中的广告系列和广告组名称不能相同
2、如有使用问题可以与我联系
PS:如果有需要用自己的模板进行批量投放的可以进入我的博客与我联系。
1 import xlrd 2 import tkinter as tk 3 4 window = tk.Tk() 5 window.title(‘Google投放广告脚本‘) 6 window.geometry(‘400x300‘) 7 8 l = tk.Label(window,text=‘请输入需要投广的文件名‘,font=(‘Arial‘,12),width=25,height=2) 9 e =tk.Entry(window,show=None) 10 l.pack() 11 e.pack() 12 13 def zhuanhuan(): 14 import os 15 # print(e.get()) 16 cwd =os.getcwd() 17 data_path = cwd +‘\‘+e.get()+‘.xlsx‘ 18 19 muban = xlrd.open_workbook(data_path) 20 xl = muban.sheets()[0] 21 22 xilie = [] 23 group =[] 24 group_price = [] 25 product_price = [] 26 sku_size = [] 27 for i in range(1,xl.nrows): 28 row = xl.row_values(i) 29 xilie.append(row[0]) 30 group.append(row[1]) 31 group_price.append(row[10]) 32 product_price.append(row[11]) 33 sku_size.append(row[9].split(‘ ‘)) 34 # print(sku_size) 35 36 file_handle = open(e.get()+‘.txt‘,mode=‘w‘) 37 file_handle.write(‘function main (){ var compaign =[‘) 38 for j in range(len(xilie)-1): 39 file_handle.write(‘"‘+xilie[j]+‘"‘+‘,‘) 40 file_handle.write(‘"‘+xilie[len(xilie)-1]+‘"]‘+‘; var group =[‘) 41 for j in range(len(group)-1): 42 file_handle.write(‘"‘+group[j]+‘"‘+‘,‘) 43 file_handle.write(‘"‘+group[len(group)-1]+‘"]‘+‘; var money =[‘) 44 for j in range(len(group_price)-1): 45 file_handle.write(‘"‘+str(group_price[j])+‘"‘+‘,‘) 46 file_handle.write(‘"‘+str(group_price[len(group_price)-1])+‘"]‘+‘; for(var i=0 ;i<compaign.length;i++){ CreateGroup(compaign[i],group[i],money[i]); } CreateProduct(group,compaign) ; CreateAd(group,compaign); } ‘ 47 ‘function CreateGroup(campaignName,adGroupName,money){ var shoppingCampaign = AdsApp.shoppingCampaigns().withCondition("CampaignName = ‘ +"‘"+‘"‘+‘ + campaignName +‘+‘"‘+"‘"+‘").get().next(); ‘ 48 ‘var adGroupOperation = shoppingCampaign.newAdGroupBuilder().withName(adGroupName).withBiddingStrategy(‘+"‘"‘MANUAL_CPC‘"‘"+‘).withStatus(‘+"‘"‘ENABLED‘"‘"+‘).withCpc‘ 49 ‘(money).build(); return true; } function CreateProduct(group,compaign) { var product =[‘) 50 for j in range(len(sku_size)): 51 file_handle.write(str(sku_size[j])+‘,‘) 52 file_handle.write(‘]; var product_money =[‘) 53 for j in range(len(product_price)-1): 54 file_handle.write(‘"‘+str(product_price[j])+‘"‘+‘,‘) 55 file_handle.write(‘"‘+str(product_price[len(product_price)-1])+‘"]; for(var i =0;i<group.length;i++){ var groups = AdsApp.shoppingAdGroups().withCondition("CampaignName = ‘ 56 +"‘"+‘" + compaign[i] + "‘ +"‘"+‘").withCondition("AdGroupName = ‘+"‘"+‘" + group[i] + "‘+"‘"+‘").get().next(); ‘ 57 +‘var child = groups.createRootProductGroup(); var root = groups.rootProductGroup(); for(var x = 0;x<product[i].length;x++){ var a = root.newChild().itemIdBuilder().withValue(product[i][x]).withBid(product_money[i]).build(); ‘ 58 ‘} } } function CreateAd(group,compaign) { for(var i =0;i<group.length;i++){ var groups = AdsApp.shoppingAdGroups().withCondition("CampaignName = ‘ 59 +"‘"+‘" + compaign[i] + "‘ +"‘"+‘").withCondition("AdGroupName = ‘+"‘"+‘" + group[i] + "‘+"‘"+‘").get().next(); ‘ 60 ‘var adOperation = groups.newAdBuilder().build(); } }‘) 61 62 file_handle.close() 63 return None 64 b = tk.Button(window,text=‘转换成脚本文件‘,width=12,height=1,command=zhuanhuan) 65 b.pack() 66 67 window.mainloop()
以上是关于Google广告批量投放脚本的主要内容,如果未能解决你的问题,请参考以下文章
Google admob 和 Facebook 受众网络可以在同一个应用程序上投放广告吗?
AdSense 使用教程: 通过让 Google 在您的网站上投放广告,帮助您从中获利