|
@@ -0,0 +1,164 @@
|
|
|
+from selenium import webdriver
|
|
|
+from selenium.webdriver import ActionChains
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
+from selenium.webdriver.support import expected_conditions as EC
|
|
|
+from selenium.webdriver.support.wait import WebDriverWait
|
|
|
+from wechat_action.send_ad_idea import IdeaAction
|
|
|
+from selenium.webdriver import ChromeOptions
|
|
|
+
|
|
|
+import time
|
|
|
+import random
|
|
|
+
|
|
|
+
|
|
|
+class SendAd():
|
|
|
+
|
|
|
+
|
|
|
+ def __init__(self, task):
|
|
|
+ self.task = task
|
|
|
+ self.task_check()
|
|
|
+ self.driver = self.get_driver()
|
|
|
+ self.ad_idea_action = IdeaAction(self.driver)
|
|
|
+
|
|
|
+ def get_driver(self):
|
|
|
+ options = ChromeOptions()
|
|
|
+
|
|
|
+ options.add_argument("--disable-dev-shm-usage")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ driver=webdriver.Chrome()
|
|
|
+ return driver
|
|
|
+
|
|
|
+ def log_in(self):
|
|
|
+ self.driver.get('https://a.weixin.qq.com/index.html')
|
|
|
+ self.driver.save_screenshot('wechat_page_start.png')
|
|
|
+
|
|
|
+ img_selector = 'body > div.old-template > div > div > div.waiting.panelContent > div.wrp_code > img'
|
|
|
+ 'body > div.old-template > div > div > div.waiting.panelContent > div.wrp_code > img'
|
|
|
+ frame_login = self.driver.find_element_by_xpath('//*[@id="login_container"]/iframe')
|
|
|
+ self.driver.switch_to.frame(frame_login)
|
|
|
+
|
|
|
+
|
|
|
+ img_url = self.driver.find_element_by_css_selector(img_selector)
|
|
|
+ print('img', img_url.get_attribute('src'))
|
|
|
+ WebDriverWait(self.driver, 100).until(lambda driver: driver.find_elements_by_link_text('广告投放'))
|
|
|
+ self.driver.save_screenshot('get_in_page.png')
|
|
|
+
|
|
|
+ def select_ad_master(self):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.driver.execute_script('''
|
|
|
+ window.scroll(100000,1000000);
|
|
|
+ var e_one=document.getElementsByClassName('Table_new__wrapper-1cpZN')[0];
|
|
|
+ e_one.scroll(10000,100000);
|
|
|
+ ''')
|
|
|
+ elements = self.driver.find_elements_by_link_text('广告投放')
|
|
|
+
|
|
|
+ elements[1].click()
|
|
|
+ time.sleep(1)
|
|
|
+
|
|
|
+
|
|
|
+ self.driver.switch_to.window(self.driver.window_handles[-1])
|
|
|
+
|
|
|
+ WebDriverWait(self.driver, 100).until(lambda driver: driver.find_element_by_class_name(
|
|
|
+ 'adui-button-hasLeftIcon'))
|
|
|
+
|
|
|
+ gg_button = self.driver.find_element_by_class_name(
|
|
|
+ 'adui-button-hasLeftIcon')
|
|
|
+ gg_button.click()
|
|
|
+
|
|
|
+ def select_ad_locations(self):
|
|
|
+
|
|
|
+ self.driver.switch_to.window(self.driver.window_handles[-1])
|
|
|
+ self.driver.execute_script('''
|
|
|
+ window.scroll(100000,0);
|
|
|
+ ''')
|
|
|
+ WebDriverWait(self.driver, 10).until(
|
|
|
+ lambda driver: self.driver.find_element_by_css_selector('#PRODUCTTYPE_WECHAT'))
|
|
|
+
|
|
|
+ wechat_gg = self.driver.find_element_by_css_selector('#PRODUCTTYPE_WECHAT')
|
|
|
+ wechat_gg.click()
|
|
|
+ localtion = self.task['localtion']
|
|
|
+ if localtion == 'gzh_bottom':
|
|
|
+
|
|
|
+ pass
|
|
|
+ if localtion == 'gzh_movie':
|
|
|
+ wechat_localtion = self.driver.find_element_by_id('pos_8')
|
|
|
+ wechat_localtion.click()
|
|
|
+ if localtion == 'pyq':
|
|
|
+ wechat_localtion = self.driver.find_element_by_css_selector(
|
|
|
+ '#wxadcontainer > div:nth-child(1) > div > div.content-2-HFBij0Uh > main > div > div:nth-child(3) > div.adui-grid-row > div:nth-child(1)')
|
|
|
+ wechat_localtion.click()
|
|
|
+ time.sleep(random.uniform(0.1, 0.3))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ next_button = self.driver.find_element_by_css_selector('#plan_next_step')
|
|
|
+ next_button.click()
|
|
|
+ self.driver.save_screenshot('set_page_localtion.png')
|
|
|
+
|
|
|
+ def set_ad_cost(self):
|
|
|
+
|
|
|
+
|
|
|
+ WebDriverWait(self.driver, 10).until(
|
|
|
+ lambda driver: self.driver.find_element_by_css_selector('#area_input > div > i'))
|
|
|
+ self.driver.find_element_by_css_selector('#area_input > div > i').click()
|
|
|
+ if self.task['localtion'] == 'gzh_botoom':
|
|
|
+ self.driver.find_element_by_class_name('icon-3cAquX1RLZ').click()
|
|
|
+ if self.task['localtion'] == 'gzh_movie':
|
|
|
+ citys = self.driver.find_elements_by_class_name('checkbox-1pfRMRqv-R')
|
|
|
+ for _ in citys:
|
|
|
+ _.click()
|
|
|
+ if self.task['localtion'] == 'pyq':
|
|
|
+ pass
|
|
|
+ day_cost = self.driver.find_element_by_css_selector('#budget_input')
|
|
|
+ day_cost.send_keys('100')
|
|
|
+ self.driver.save_screenshot('set_page_cost.png')
|
|
|
+ self.driver.find_element_by_css_selector('#target_next_step').click()
|
|
|
+
|
|
|
+ def set_ad_idea(self):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if self.task['localtion'] == 'gzh_bottom':
|
|
|
+ self.ad_idea_action.idea_pic_gzh_bottom()
|
|
|
+ if self.task['localtion'] == 'gzh_movie':
|
|
|
+ self.ad_idea_action.idea_movie_gzh_movie()
|
|
|
+ if self.task['localtion'] == 'pyq':
|
|
|
+ pass
|
|
|
+
|
|
|
+ next_button = self.driver.find_element_by_class_name('adui-button-primary')
|
|
|
+ next_button.click()
|
|
|
+
|
|
|
+ def push_ad(self):
|
|
|
+
|
|
|
+ time.sleep(random.uniform(3, 4))
|
|
|
+ self.driver.find_element_by_class_name('icon-3cAquX1RLZ').click()
|
|
|
+ time.sleep(random.uniform(0.5, 1))
|
|
|
+ self.driver.save_screenshot('push_page.png')
|
|
|
+ self.driver.find_element_by_class_name('adui-button-primary').click()
|
|
|
+
|
|
|
+ def task_check(self):
|
|
|
+
|
|
|
+ if 'master' not in self.task.keys() or 'localtion' not in self.task.keys():
|
|
|
+ exit()
|
|
|
+
|
|
|
+ def run(self):
|
|
|
+
|
|
|
+ self.log_in()
|
|
|
+ self.select_ad_master()
|
|
|
+ self.select_ad_locations()
|
|
|
+ self.set_ad_cost()
|
|
|
+ self.set_ad_idea()
|
|
|
+ self.push_ad()
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ task = {'master': '', 'localtion': 'gzh_movie'}
|
|
|
+ SendAd(task).run()
|