Browse Source

MOD:落地页一键关注添加

cxyu 3 years ago
parent
commit
367b802171
2 changed files with 65 additions and 14 deletions
  1. 64 13
      wechat_action/create_ad_layout.py
  2. 1 1
      wechat_action/create_ad_plan.py

+ 64 - 13
wechat_action/create_ad_layout.py

@@ -25,13 +25,21 @@ class CreateAd:
         # 进入创建页面
         self.driver.find_element_by_id('material').click()
 
-        WebDriverWait(self.driver, 10).until(lambda driver: driver.find_element_by_class_name('ui-fl-r'))
-        create_element = self.driver.find_element_by_class_name('ui-fl-r')
+        try:
+            # 落地页内容有的账户有,有的无,无的默认等5s
+            WebDriverWait(self.driver, 5).until(lambda driver: self.driver.find_elements_by_xpath(
+                '//*[@class="adui-table-tr"]'))
+        except:
+            pass
+        WebDriverWait(self.driver, 10).until(lambda driver: self.driver.find_element_by_xpath(
+            '//*[@class="ui-fl-r adui-button-base adui-button-primary adui-button-small"]'))
+        create_element = self.driver.find_element_by_xpath(
+            '//*[@class="ui-fl-r adui-button-base adui-button-primary adui-button-small"]')
         WebDriverWait(self.driver, 10).until(
             lambda driver: create_element.is_displayed() and create_element.is_enabled())
         # is_displayed 和 is_enabled 没有那么快就可以使用
         time.sleep(0.1)
-        self.driver.find_element_by_class_name('ui-fl-r').click()
+        create_element.click()
         WebDriverWait(self.driver, 5).until(lambda driver: driver.find_element_by_css_selector(
             '#wxadcontainer > div:nth-child(1) > div:nth-child(2) > div.dialog-1fj_N480ZT > div > div > div:nth-child(1) > div.dialogCardFooter-17KpBD1lgN > button'))
         self.driver.find_element_by_css_selector(
@@ -64,10 +72,24 @@ class CreateAd:
 
     def set_head_assemb(self, info):
         def single_page_set():
-            # TODO:选择图片之后,还有一些其他选项
             self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/div[1]/div/div[1]/div/div').click()
             time.sleep(random.uniform(0.1, 0.2))
 
+            # 设置图片格式
+            if info['content']['adSite'] != '朋友圈信息流':
+                self.driver.find_elements_by_xpath('//*[@class="adui-radio-indicator"]')[1].click()
+            elif info['content']['outerStyle'] != '常规广告':
+                select_e = self.driver.find_elements_by_xpath('//*[@class="adui-select-selection-item"]')
+                for _ in select_e:
+                    if _.text == '常规广告':
+                        _.click()
+                time.sleep(0.1)
+                select_e = self.driver.find_elements_by_xpath('//*[@class="adui-select-item-option-content"]')
+                for _ in select_e:
+                    if _.text == '卡片广告':
+                        _.click()
+
+            # 上传图片
             file_name = re.split('\/', info['content']['url'])[-1]
             self.driver.find_element_by_class_name('upload-img-item-inner-2gsg7NjaZ8').click()
             WebDriverWait(self.driver, 10).until(
@@ -248,7 +270,8 @@ class CreateAd:
         # 设置头部组件
         pass
 
-    def set_page(self, page_link):
+    def set_page(self, config_info):
+        page_link = config_info['url']
         # 设置图片模块
         self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[1]/div/div').click()
         time.sleep(random.uniform(0.1, 0.2))
@@ -321,6 +344,21 @@ class CreateAd:
                     _.click()
         except Exception as e:
             logging.info(e)
+        # 设置文本边距
+        if config_info['marginTop'] != 0 or config_info['marginBottom'] != 0:
+            distance_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
+            distance_buttons_can_use = []
+            for _ in distance_buttons:
+                if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '0':
+                    distance_buttons_can_use.append(_)
+            distance_buttons_can_use[0].click()
+            for i in range(4):
+                distance_buttons_can_use[0].send_keys(Keys.BACKSPACE)
+            distance_buttons_can_use[0].send_keys(config_info['marginTop'])
+            distance_buttons_can_use[1].click()
+            for i in range(4):
+                distance_buttons_can_use[1].send_keys(Keys.BACKSPACE)
+            distance_buttons_can_use[1].send_keys(config_info['marginBottom'])
         logging.info('图片模块设置结束')
 
     def set_content(self, config_info):
@@ -338,7 +376,7 @@ class CreateAd:
                 _.send_keys(config_info['text'])
 
         # 设置颜色
-        if config_info['color'] != '595959':
+        if config_info['color'] != '#595959':
             color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
             c_buttons_can_use = []
             for _ in color_buttons:
@@ -355,7 +393,6 @@ class CreateAd:
 
         # 设置是否加粗
         if config_info['fontWeight'] != 'normal':
-            # TODO:新格式  文本是否加粗,还不知道
             big_elements = self.driver.find_elements_by_class_name('adui-button-content')
             for _ in big_elements:
                 if _.text == '加粗' and _.is_displayed() and _.is_enabled():
@@ -363,7 +400,6 @@ class CreateAd:
 
         # 设置文本位置
         if config_info['textAlign'] != 'left':
-            # TODO:新格式  文本位置设置,还不知道
             loc_buttons = self.driver.find_elements_by_xpath(
                 "//div[contains(@class, 'adui-button-group_banner')]//button")
             loc_buttons_can_use = []
@@ -390,8 +426,12 @@ class CreateAd:
             for _ in str_num_buttons:
                 if _.is_displayed() and _.is_enabled():
                     str_num_can_use.append(_)
-            str_num_map = {14: 0, 16: 1, 18: 2, 20: 3, 24: 4, 36: 5}
-            str_num_can_use[str_num_map[config_info['fontSize']]].click()
+            # str_num_map = {14: 0, 15: 1, 16: 2, 18: 3, 20: 4, 24: 5, 36: 6}
+            # str_num_can_use[str_num_map[config_info['fontSize']]].click()
+
+            for _ in str_num_can_use:
+                if _.text == str(config_info['fontSize']):
+                    _.click()
 
         # 设置文本边距
         if config_info['marginTop'] != 22 or config_info['marginBottom'] != 22:
@@ -413,9 +453,20 @@ class CreateAd:
         # TODO:是否一键关注
 
         # 设置关注按钮
-        # 1.设置button文本内容 2.是否加粗 3.设置字体颜色,边框颜色,填充色 4.设置边距
-
+        # 0.是否一键关注 1.设置button文本内容 2.是否加粗 3.设置字体颜色,边框颜色,填充色 4.设置边距
         self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[4]/div[2]/div/div').click()
+
+        # 开始设置一键关注
+        if 'follow' in config_info.keys():
+            if not config_info['follow']:
+                time.sleep(0.1)
+                follow_bs = self.driver.find_elements_by_xpath(
+                    '//*[@class="form-caption-3Xp3o6Drwf"]/div/span')
+
+                for _ in follow_bs:
+                    if _.is_displayed() and _.is_enabled():
+                        _.click()
+
         # 文本设置
         input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
         for _ in input_elements:
@@ -665,7 +716,7 @@ class CreateAd:
 
             for _ in layout['content']:
                 if _['type'] == 'img':
-                    self.set_page(page_link=_['content']['url'])
+                    self.set_page(_['content'])
                 if _['type'] == 'txt':
                     self.set_content(_['content'])
                 if _['type'] == 'followAcc':

+ 1 - 1
wechat_action/create_ad_plan.py

@@ -253,7 +253,7 @@ class CreateAdPlan():
         age_elements[0].click()
         time.sleep(0.1)
         age_list = self.task['human_info_parameter']['age_list']
-        # TODO:66就是65以上
+        # TODO:有时间规整一下,前端传过来的数据,dict中的值  数字全为字符串,或者全为数字
 
         # 256,一截,[14(17),24][25,32][33,40][41,48][49,56][57,64]
         if age_list[0] == 14: