Bläddra i källkod

MOD:文本输入修改

cxyu 3 år sedan
förälder
incheckning
0419288ded
2 ändrade filer med 27 tillägg och 5 borttagningar
  1. 24 1
      wechat_action/create_ad_layout.py
  2. 3 4
      wechat_action/create_ad_plan.py

+ 24 - 1
wechat_action/create_ad_layout.py

@@ -373,7 +373,30 @@ class CreateAd:
         self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[5]/div/div').click()
         self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[2]/div[5]/div/div').click()
         time.sleep(random.uniform(0.2, 0.3))
         time.sleep(random.uniform(0.2, 0.3))
         input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
         input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
-        pyperclip.copy(config_info['text'])
+        # pyperclip.copy(config_info['text'])
+        js_base = '''
+        function copyToClipboard(text) {
+            var dummy = document.createElement("textarea");
+            // to avoid breaking orgain page when copying more words
+            // cant copy when adding below this code
+            // dummy.style.display = 'none'
+            document.body.appendChild(dummy);
+            //Be careful if you use texarea. setAttribute('value', value), which works with "input" does not work with "textarea". – Eduard
+            dummy.value = text;
+            dummy.select();
+            document.execCommand("copy");
+            document.body.removeChild(dummy);
+        }
+        '''
+        content_change = config_info['text']
+
+        content_change = content_change.replace("\\", "\\\\")
+        content_change = content_change.replace('\n', '\\n')
+        content_change = content_change.replace('\n', '\\n')
+        content_change = content_change.replace("'", "\'")
+
+        js_base = js_base + '''copyToClipboard('{}');'''.format(content_change)
+        self.driver.execute_script(js_base)
         for _ in input_elements:
         for _ in input_elements:
             if _.is_enabled() and _.is_displayed():
             if _.is_enabled() and _.is_displayed():
                 _.send_keys(Keys.CONTROL, 'v')
                 _.send_keys(Keys.CONTROL, 'v')

+ 3 - 4
wechat_action/create_ad_plan.py

@@ -37,7 +37,7 @@ class CreateAdPlan():
         # TODO:设置完之后,test函数中进行对应修改
         # TODO:设置完之后,test函数中进行对应修改
         logging.info('开始设置cpm')
         logging.info('开始设置cpm')
         if self.task['cpm']['cpm_set'] == '2':
         if self.task['cpm']['cpm_set'] == '2':
-            self.driver.save_screenshot('cpm{}.png'.format(time.time()))
+            # self.driver.save_screenshot('cpm{}.png'.format(time.time()))
             self.driver.find_element_by_xpath(
             self.driver.find_element_by_xpath(
                 '//*[@id="wxadcontainer"]/div[1]/div/div[2]/main/div/div[2]/div[1]/div/div[2]/div/div[1]/section[2]/form/div/div[1]/div[1]/button[2]/span').click()
                 '//*[@id="wxadcontainer"]/div[1]/div/div[2]/main/div/div[2]/div[1]/div/div[2]/div/div[1]/section[2]/form/div/div[1]/div[1]/button[2]/span').click()
             time.sleep(0.1)
             time.sleep(0.1)
@@ -158,7 +158,7 @@ class CreateAdPlan():
 
 
             time.sleep(0.2)
             time.sleep(0.2)
 
 
-        self.driver.save_screenshot('time-{}.png'.format(time.time()))
+        # self.driver.save_screenshot('time-{}.png'.format(time.time()))
         time.sleep(0.1)
         time.sleep(0.1)
 
 
     def set_ad_human_location(self):
     def set_ad_human_location(self):
@@ -369,8 +369,7 @@ class CreateAdPlan():
                     return self.run(sql_session, err_num=err_num + 1)
                     return self.run(sql_session, err_num=err_num + 1)
         except Exception as e:
         except Exception as e:
             raise
             raise
-            time.sleep(5)
-            self.driver.save_screenshot('liuyi{}.png'.format(time.time()))
+            # self.driver.save_screenshot('liuyi{}.png'.format(time.time()))
             time.sleep(5)
             time.sleep(5)
 
 
             # TODO:有空时讲 e 内容设置为原始内容
             # TODO:有空时讲 e 内容设置为原始内容