|
@@ -24,24 +24,21 @@ class CreateAd:
|
|
|
|
|
|
def get_into_create_page(self):
|
|
|
# 进入创建页面
|
|
|
+ logging.info('开始进入创建页面')
|
|
|
self.driver.find_element_by_id('material').click()
|
|
|
- try:
|
|
|
- # 落地页内容有的账户有,有的无,无的默认等5s
|
|
|
- WebDriverWait(self.driver, 5).until(lambda driver: len(self.driver.find_elements_by_xpath(
|
|
|
- '//*[@class="adui-table-cell"]')))
|
|
|
- for i in self.driver.find_elements_by_xpath(
|
|
|
- '//*[@class="adui-table-cell"]'):
|
|
|
- WebDriverWait(self.driver, 5).until(lambda driver: i.is_displayed() and i.is_enabled())
|
|
|
- except Exception as e:
|
|
|
- logging.error(str(e))
|
|
|
- time.sleep(5)
|
|
|
- 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())
|
|
|
- create_element.click()
|
|
|
+ for i in range(10):
|
|
|
+ try:
|
|
|
+ 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())
|
|
|
+ create_element.click()
|
|
|
+ except Exception as e:
|
|
|
+ pass
|
|
|
+ if i == 10:
|
|
|
+ raise ValueError('点击新建推广页 出错')
|
|
|
logging.info('点击新建推广页 结束')
|
|
|
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'))
|
|
@@ -505,9 +502,10 @@ class CreateAd:
|
|
|
for _ in input_elements:
|
|
|
if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '关注公众号':
|
|
|
_.click()
|
|
|
- _.clear()
|
|
|
- for i in range(10):
|
|
|
- _.send_keys(Keys.BACKSPACE)
|
|
|
+ # for i in range(10):
|
|
|
+ # _.send_keys(Keys.BACKSPACE)
|
|
|
+ _.send_keys(Keys.CONTROL + 'a')
|
|
|
+ _.send_keys(Keys.BACKSPACE)
|
|
|
_.send_keys(config_info['text'])
|
|
|
|
|
|
# 文本是否加粗
|
|
@@ -632,19 +630,27 @@ class CreateAd:
|
|
|
|
|
|
def send_file(self, file_link, err_num=0):
|
|
|
# 下载图片,存储于
|
|
|
-
|
|
|
- if not os.path.exists(self.img_dir):
|
|
|
- os.makedirs(self.img_dir)
|
|
|
- link_pra = re.split('\/', file_link)
|
|
|
- file_path = os.getcwd() + '/' + self.img_dir + '/' + link_pra[-1]
|
|
|
- rsp = requests.get(file_link)
|
|
|
- with open(file_path, 'wb') as f:
|
|
|
- f.write(rsp.content)
|
|
|
- # 有问题,暂时不使用
|
|
|
- self.driver.execute_script('location.reload();')
|
|
|
- self.driver.find_element_by_xpath('//*[@id="wxadcontainer"]/div[1]/div[2]/div[4]/input').send_keys(file_path)
|
|
|
+ try:
|
|
|
+ if not os.path.exists(self.img_dir):
|
|
|
+ os.makedirs(self.img_dir)
|
|
|
+ link_pra = re.split('\/', file_link)
|
|
|
+ file_path = os.getcwd() + '/' + self.img_dir + '/' + link_pra[-1]
|
|
|
+ rsp = requests.get(file_link, timeout=0.5)
|
|
|
+ with open(file_path, 'wb') as f:
|
|
|
+ f.write(rsp.content)
|
|
|
+ # 有问题,暂时不使用
|
|
|
+ self.driver.execute_script('location.reload();')
|
|
|
+ self.driver.find_element_by_xpath('//*[@id="wxadcontainer"]/div[1]/div[2]/div[4]/input').send_keys(
|
|
|
+ file_path)
|
|
|
+ except:
|
|
|
+ if err_num < 20:
|
|
|
+ self.send_file(file_link, err_num=err_num + 1)
|
|
|
|
|
|
def send_file_alone(self, layout):
|
|
|
+ def check_file():
|
|
|
+ # TODO:检查是否需要上传
|
|
|
+ pass
|
|
|
+
|
|
|
def get_url(v_info):
|
|
|
if 'url' in v_info.keys():
|
|
|
file_set.add(v_info['url'])
|
|
@@ -736,14 +742,16 @@ class CreateAd:
|
|
|
if len(result_json['landing_page_list']):
|
|
|
logging.info('对应落地页存在于微信后台')
|
|
|
return True
|
|
|
+ else:
|
|
|
+ logging.info('对应落地页不存在于微信后台')
|
|
|
|
|
|
def remove_all_file(self):
|
|
|
- shutil.rmtree(os.getcwd() + '/' + self.img_dir)
|
|
|
- pass
|
|
|
+ try:
|
|
|
+ shutil.rmtree(os.getcwd() + '/' + self.img_dir)
|
|
|
+ except Exception as e:
|
|
|
+ logging.info(str(e))
|
|
|
|
|
|
def create_layout(self, layout, sql_session, err_num=0):
|
|
|
- #
|
|
|
-
|
|
|
try:
|
|
|
self.send_file_alone(layout)
|
|
|
self.set_advertisement_sign(layout_name=layout['layoutName'])
|