Last active
June 5, 2022 18:50
-
-
Save m0pfin/40673bccbff14f0ef8ac99f0d7e7d18a to your computer and use it in GitHub Desktop.
Почти автоматический залив рекламы в Tik-Tok ADS в связке Selenium & INDIGO (MLA)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.firefox import options | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import Select | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
import requests | |
import time | |
import random | |
import string | |
profile = open('load.txt', 'r') | |
lines = profile.readlines() | |
profile_id = lines[0].strip() | |
print('ID profile: %s' % (profile_id)) | |
#TODO replace with existing profile ID. Define the ID of the browser profile, where the code will be executed. | |
mla_profile_id = str(profile_id) | |
mla_url = 'http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId='+mla_profile_id | |
""" | |
Send GET request to start the browser profile by profileId. Returns response in the following format: '{"status":"OK","value":"http://127.0.0.1:XXXXX"}', where XXXXX is the localhost port on which browser profile is launched. Please make sure that you have Multilogin listening port set to 35000. Otherwise please change the port value in the url string | |
""" | |
resp = requests.get(mla_url) | |
json = resp.json() | |
#Define DesiredCapabilities | |
opts = options.DesiredCapabilities() | |
#Instantiate the Remote Web Driver to connect to the browser profile launched by previous GET request | |
driver = webdriver.Remote(command_executor=json['value'], desired_capabilities={}) | |
#Perform automation | |
driver.get('https://ads.tiktok.com/i18n/campaign/ad-campaign/create') | |
time.sleep(10) | |
#assert "Multilogin - Replace Multiple Computers With Virtual Browser Profiles - Multilogin" in driver.title | |
#Click the link | |
driver.find_element(By.XPATH, '//*[@id="app"]/section/div[2]/section/div/div/div[1]/div[2]/div[1]/div/div[3]/span/button[1]/span').click() | |
time.sleep(1) | |
print ("Нажали начать заново") | |
driver.find_element(By.XPATH, '//*[@id="campaign_objective_conversion"]/div[2]/div[1]/span').click() | |
time.sleep(1) | |
print ("Конверсии") | |
driver.find_element(By.XPATH, '//*[@id="cp-submit-btn"]/span').click() | |
time.sleep(8) | |
print ("Далее") | |
driver.execute_script('document.evaluate("//*[@id=\'ag-promotion-use-tiktok-pixel-input\']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
driver.find_element(By.XPATH, '/html/body/div[5]/ul/li').click() | |
#driver.execute_script('document.evaluate("//*[@id=\'ag-promotion-use-tiktok-pixel-084161\']/div/div[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
print ("Выбрали пиксель") | |
driver.execute_script('document.evaluate("//*[@id=\'ag-promotion-use-opt-event-input\']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
driver.execute_script('document.evaluate("//*[@id=\'ag-promotion-use-opt-event-96\']/div/div", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
print ("Выбрали событие") | |
#driver.find_element_by_css_selector("#ag-placement-select > span.vi-radio__input > span").click() | |
driver.execute_script('document.evaluate("//*[@id=\'ag-placement-select\']/span[1]/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(1) | |
print ("Плейсменты") | |
driver.find_element_by_css_selector("#ag-placement-select-1000 > span.vi-checkbox__input.is-checked > span").click() | |
time.sleep(1) | |
print ("убираем 1") | |
driver.find_element_by_css_selector("#ag-placement-select-9000 > span.vi-checkbox__input.is-checked > span").click() | |
time.sleep(1) | |
print ("Убираем 2") | |
#driver.find_element(By.XPATH, '//*[@id="ag-placement-comment-switch"]/div/div[1]/span').click() | |
driver.execute_script('document.evaluate("//*[@id=\'ag-placement-comment-switch\']/div/div[1]/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
print ("Комменты оф") | |
#driver.find_element(By.XPATH, '//*[@id="ag-placement-download-switch"]/div/div[1]/span').click() | |
driver.execute_script('document.evaluate("//*[@id=\'ag-placement-download-switch\']/div/div[1]/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
print ("Скачка оф") | |
#driver.find_element(By.XPATH, '//*[@id="ag-creative-type-switch"]/label/div/div/span').click() | |
driver.execute_script('document.evaluate("//*[@id=\'ag-creative-type-switch\']/label/div/div/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
print ("Авто оптимиз крео") | |
# выбираем Россию | |
driver.execute_script('document.evaluate("//*[@id=\'country0\']/div/div[1]/div[1]/div/input", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
driver.execute_script('document.evaluate("//*[@id=\'country0\']/div/div[1]/div[2]/div/div[1]/div/div/div[9]/div[1]/span[2]/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
#driver.find_element(By.XPATH, '//*[@id="country0"]/div/div[1]/div[2]/div/div[1]/div/div/div[9]/div[1]/span[2]/span').click() | |
time.sleep(2) | |
print ("Выбрали страну") | |
#Gender | |
#man = driver.find_element(By.XPATH, '//*[@id="target"]/div[2]/div[7]/div[1]/div[1]/div/div/label[2]/span').click() | |
time.sleep(2) | |
#woman = | |
#driver.find_element(By.XPATH, '//*[@id="target"]/div[2]/div[7]/div[1]/div[1]/div/div/label[3]/span').click() | |
driver.execute_script('document.evaluate("//*[@id=\'target\']/div[2]/div[7]/div[1]/div[1]/div/div/label[3]/span", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();') | |
time.sleep(2) | |
print ("Выбрали баб") | |
budget = driver.find_element(By.XPATH, "//input[@id='ag-budget-input']").send_keys("2000") | |
time.sleep(2) | |
#budget.send_keys('2000') # GG phone name | |
print ("Бюджет выбрали") | |
driver.find_element(By.XPATH, '//*[@id="ag-create-submit-btn"]/span').click() | |
time.sleep(10) | |
print ("Далее") | |
name_acc = driver.find_element(By.XPATH, "//*[@id='display_name']/div/div[1]/input").send_keys("Hers Ovalk") | |
time.sleep(2) | |
#Загрузка креатива пока не реализована, нехватает мозгов | |
#driver.execute_script('document.evaluate("//*[@id=\'adsDetail\']/div[2]/div/div[2]/div[3]/div[1]/div/div/div/div[1]/div/input", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute("style", "display: block;");') | |
#filess = driver.find_element(By.XPATH, "//*[@id='adsDetail']/div[2]/div/div[2]/div[3]/div[1]/div/div/div/div[1]/div/input") | |
#filess.sendKeys("C://Users/m0pfin/Downloads/Creative/gsb1/gs1609.mp4") | |
#Загрузка креатива пока не реализована, нехватает мозгов | |
creo_text = driver.find_element(By.XPATH, "//*[@id='ad-detail-display-text-0']").send_keys("Текст креатива") | |
time.sleep(2) | |
#budget.send_keys('2000') # GG phone name | |
print ("ввели текст") | |
creo_link = driver.find_element(By.XPATH, "//*[@id='websiteUrl']").send_keys("https://site.ru/?pokedova=32033200230") | |
time.sleep(2) | |
#budget.send_keys('2000') # GG phone name | |
print ("ввели ссылку") | |
#driver.find_element(By.XPATH, '//*[@id="ad-submit-btn"]/span').click() | |
print ("Опубликовать") | |
# Удаляем ID профиля из файла | |
profile = open('load.txt', 'w') | |
profile.writelines(lines[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment