|
@@ -5,6 +5,7 @@ from selenium.webdriver.common.by import By
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
|
from selenium.webdriver import ChromeOptions
|
|
|
+from selenium.webdriver.common.keys import Keys
|
|
|
import logging
|
|
|
import time
|
|
|
import random
|
|
@@ -40,6 +41,20 @@ class CreateAd:
|
|
|
# 创建编排
|
|
|
pass
|
|
|
|
|
|
+ def set_background_color(self):
|
|
|
+ color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
|
|
|
+ c_buttons_can_use = []
|
|
|
+ for _ in color_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ c_buttons_can_use.append(_)
|
|
|
+ c_buttons_can_use[0].click()
|
|
|
+ time.sleep(random.uniform(0.2, 0.3))
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == 'FFFFFF':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('F7F7F7')
|
|
|
+
|
|
|
def set_head_assemb(self, info):
|
|
|
def single_page_set():
|
|
|
|
|
@@ -67,7 +82,7 @@ class CreateAd:
|
|
|
_.click()
|
|
|
chose_over = True
|
|
|
break
|
|
|
- if chose_over or len(can_use_button)==0:
|
|
|
+ if chose_over or len(can_use_button) == 0:
|
|
|
break
|
|
|
# 翻到最后一页时停止
|
|
|
page_text = self.driver.find_element_by_class_name('count_small-37CcvfzoTl').text
|
|
@@ -132,7 +147,6 @@ class CreateAd:
|
|
|
for _ in input_elements:
|
|
|
if '输入关键词搜索素材' in _.get_attribute('placeholder'):
|
|
|
input_find_element = _
|
|
|
- from selenium.webdriver.common.keys import Keys
|
|
|
|
|
|
for _ in info_v:
|
|
|
file_name = os.path.basename(_)
|
|
@@ -166,6 +180,53 @@ class CreateAd:
|
|
|
|
|
|
logging.info('头版多图选择 结束')
|
|
|
|
|
|
+ def movie_set():
|
|
|
+ file_name = os.path.basename(info_v)
|
|
|
+ self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/div[1]/div/div[3]/div/div').click()
|
|
|
+ self.driver.find_element_by_xpath('//*[@class="comptEditButton-2JsnAFdOGZ"]').click()
|
|
|
+
|
|
|
+ WebDriverWait(self.driver, 100).until(
|
|
|
+ lambda x: len([_ for _ in self.driver.find_elements_by_class_name('title-29sncpKgTl') if
|
|
|
+ _.is_displayed() and _.is_enabled()]) > 0)
|
|
|
+ #
|
|
|
+ turn_page_buttons = self.driver.find_elements_by_class_name('paginationIcon-1EfoH0sNRF')
|
|
|
+ can_use_button = []
|
|
|
+ for _ in turn_page_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ can_use_button.append(_)
|
|
|
+ # 不断翻页获取到元素为止
|
|
|
+ chose_over = False
|
|
|
+ while True:
|
|
|
+ page_elements = self.driver.find_elements_by_class_name('title-29sncpKgTl')
|
|
|
+ for _ in page_elements:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ if file_name in _.text:
|
|
|
+ _.click()
|
|
|
+ chose_over = True
|
|
|
+ break
|
|
|
+ if chose_over or len(can_use_button) == 0:
|
|
|
+ # can_use_button 数量说明是否可以翻页,如果不可以翻页,则直接停止
|
|
|
+ break
|
|
|
+ # 翻到最后一页时停止
|
|
|
+ page_text_elements = self.driver.find_elements_by_class_name('count_small-37CcvfzoTl')
|
|
|
+ for _ in page_text_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ page_text = _.text
|
|
|
+ page_text_element = _
|
|
|
+
|
|
|
+ page_nums = re.findall('\d+', page_text)
|
|
|
+ if int(page_nums[0].strip()) == int(page_nums[1].strip()):
|
|
|
+ break
|
|
|
+ # 翻页
|
|
|
+ can_use_button[2].click()
|
|
|
+ # 确保翻页成功
|
|
|
+ WebDriverWait(self.driver, 10).until(
|
|
|
+ lambda x: page_text != page_text_element.text)
|
|
|
+ sc_buttons = self.driver.find_elements_by_id('test_material_container_confirm')
|
|
|
+ for _ in sc_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ _.click()
|
|
|
+
|
|
|
info_key = list(info.keys())[0]
|
|
|
info_v = info[info_key]
|
|
|
|
|
@@ -173,6 +234,9 @@ class CreateAd:
|
|
|
single_page_set()
|
|
|
if info_key == 'multi_page':
|
|
|
multi_page_set()
|
|
|
+ if info_key == 'movie':
|
|
|
+ movie_set()
|
|
|
+
|
|
|
# 设置头部组件
|
|
|
pass
|
|
|
|
|
@@ -190,7 +254,6 @@ class CreateAd:
|
|
|
lambda x: len([_ for _ in self.driver.find_elements_by_class_name('title-29sncpKgTl') if
|
|
|
_.is_displayed() and _.is_enabled()]) > 0)
|
|
|
|
|
|
-
|
|
|
turn_page_buttons = self.driver.find_elements_by_class_name('paginationIcon-1EfoH0sNRF')
|
|
|
can_use_button = []
|
|
|
for _ in turn_page_buttons:
|
|
@@ -206,8 +269,8 @@ class CreateAd:
|
|
|
_.click()
|
|
|
chose_over = True
|
|
|
break
|
|
|
- if chose_over or len(can_use_button)==0:
|
|
|
- #can_use_button 数量说明是否可以翻页,如果不可以翻页,则直接停止
|
|
|
+ if chose_over or len(can_use_button) == 0:
|
|
|
+ # can_use_button 数量说明是否可以翻页,如果不可以翻页,则直接停止
|
|
|
break
|
|
|
# 翻到最后一页时停止
|
|
|
page_text_elements = self.driver.find_elements_by_class_name('count_small-37CcvfzoTl')
|
|
@@ -237,7 +300,7 @@ class CreateAd:
|
|
|
'btnFist-uueBS6DQFa')
|
|
|
WebDriverWait(self.driver, 4).until(
|
|
|
lambda x: (_.is_displayed() and _.is_enabled()))
|
|
|
- #已经出现但任需要等待
|
|
|
+ # 已经出现但任需要等待
|
|
|
time.sleep(1)
|
|
|
_.click()
|
|
|
|
|
@@ -249,23 +312,174 @@ class CreateAd:
|
|
|
_.click()
|
|
|
except Exception as e:
|
|
|
logging.info(e)
|
|
|
- pass
|
|
|
logging.info('图片模块设置结束')
|
|
|
|
|
|
- def set_title(self):
|
|
|
+ def set_title(self, title_content):
|
|
|
# 设置标题模块
|
|
|
- pass
|
|
|
+ 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))
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ _.send_keys(title_content)
|
|
|
+
|
|
|
+ color_buttons = self.driver.find_elements_by_class_name('adui-cp-picker')
|
|
|
+ c_buttons_can_use = []
|
|
|
+ for _ in color_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ c_buttons_can_use.append(_)
|
|
|
+ c_buttons_can_use[1].click()
|
|
|
+ time.sleep(random.uniform(0.2, 0.3))
|
|
|
+
|
|
|
+ input_elements = self.driver.find_elements_by_tag_name('input')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '595959':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('DE2821')
|
|
|
+ big_elements = self.driver.find_elements_by_class_name('adui-button-content')
|
|
|
+ for _ in big_elements:
|
|
|
+ if _.text == '加粗' and _.is_displayed() and _.is_enabled():
|
|
|
+ _.click()
|
|
|
+ loc_buttons = self.driver.find_elements_by_xpath("//div[contains(@class, 'adui-button-group_banner')]//button")
|
|
|
+ loc_buttons_can_use = []
|
|
|
+ for _ in loc_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ loc_buttons_can_use.append(_)
|
|
|
+ loc_buttons_can_use[1].click()
|
|
|
|
|
|
- def set_content(self):
|
|
|
+ str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection__rendered']")
|
|
|
+ str_buttons_can_use = []
|
|
|
+ for _ in str_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ str_buttons_can_use.append(_)
|
|
|
+ str_buttons_can_use[1].click()
|
|
|
+ time.sleep(random.uniform(1, 3))
|
|
|
+
|
|
|
+ str_num_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-dropdown-menu-item']")
|
|
|
+ str_num_can_use = []
|
|
|
+ for _ in str_num_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ str_num_can_use.append(_)
|
|
|
+ str_num_can_use[4].click()
|
|
|
+
|
|
|
+ def set_content(self, content_content):
|
|
|
# 输入文本内容
|
|
|
- pass
|
|
|
+ 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))
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//textarea[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed():
|
|
|
+ _.send_keys(content_content)
|
|
|
+ str_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-selection__rendered']")
|
|
|
+ str_buttons_can_use = []
|
|
|
+ for _ in str_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ str_buttons_can_use.append(_)
|
|
|
+ str_buttons_can_use[1].click()
|
|
|
+ time.sleep(random.uniform(1, 3))
|
|
|
+ str_num_buttons = self.driver.find_elements_by_xpath("//*[@class='adui-select-dropdown-menu-item']")
|
|
|
+ str_num_can_use = []
|
|
|
+ for _ in str_num_buttons:
|
|
|
+ if _.is_displayed() and _.is_enabled():
|
|
|
+ str_num_can_use.append(_)
|
|
|
+ str_num_can_use[3].click()
|
|
|
|
|
|
- def set_follow_button(self):
|
|
|
- # TODO:先暂定设置三种格式
|
|
|
+ def set_follow_button(self, button_type):
|
|
|
# 设置关注按钮
|
|
|
+ self.driver.find_element_by_xpath('//*[@id="stage-sidebar"]/section/div[4]/div[2]/div/div').click()
|
|
|
+ if button_type == 1:
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ 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)
|
|
|
+ _.send_keys('保存阅读记录')
|
|
|
+ big_elements = self.driver.find_elements_by_xpath('//span[@class="adui-button-content"]')
|
|
|
+ for _ in big_elements:
|
|
|
+ if _.text == '加粗' and _.is_displayed() and _.is_enabled():
|
|
|
+ _.click()
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '07C160':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('DE2821')
|
|
|
+ if button_type == 2:
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ 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)
|
|
|
+ _.send_keys('点击此处,继续阅读')
|
|
|
+ big_elements = self.driver.find_elements_by_xpath('//span[@class="adui-button-content"]')
|
|
|
+ for _ in big_elements:
|
|
|
+ if _.text == '加粗' and _.is_displayed() and _.is_enabled():
|
|
|
+ _.click()
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '07C160':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('DE2821')
|
|
|
+ size_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ size_buttons_can_use = []
|
|
|
+ for _ in size_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '28':
|
|
|
+ size_buttons_can_use.append(_)
|
|
|
+ size_buttons_can_use[0].click()
|
|
|
+ for i in range(4):
|
|
|
+ size_buttons_can_use[0].send_keys(Keys.BACKSPACE)
|
|
|
+ size_buttons_can_use[0].send_keys('0')
|
|
|
+ size_buttons_can_use[1].click()
|
|
|
+ for i in range(4):
|
|
|
+ size_buttons_can_use[1].send_keys(Keys.BACKSPACE)
|
|
|
+ size_buttons_can_use[1].send_keys('0')
|
|
|
+
|
|
|
+ if button_type == 3:
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ 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)
|
|
|
+ _.send_keys('点我,继续阅读')
|
|
|
+ big_elements = self.driver.find_elements_by_xpath('//span[@class="adui-button-content"]')
|
|
|
+ for _ in big_elements:
|
|
|
+ if _.text == '加粗' and _.is_displayed() and _.is_enabled():
|
|
|
+ _.click()
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '07C160':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('FFFFFF')
|
|
|
+ input_elements = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ for _ in input_elements:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == 'FFFFFF':
|
|
|
+ _.click()
|
|
|
+ _.send_keys('DE2821')
|
|
|
+ break
|
|
|
+ size_buttons = self.driver.find_elements_by_xpath('//input[@class="adui-input-base"]')
|
|
|
+ size_buttons_can_use = []
|
|
|
+ for _ in size_buttons:
|
|
|
+ if _.is_enabled() and _.is_displayed() and _.get_attribute("value") == '28':
|
|
|
+ size_buttons_can_use.append(_)
|
|
|
+ size_buttons_can_use[0].click()
|
|
|
+ for i in range(4):
|
|
|
+ size_buttons_can_use[0].send_keys(Keys.BACKSPACE)
|
|
|
+ size_buttons_can_use[0].send_keys('0')
|
|
|
+ size_buttons_can_use[1].click()
|
|
|
+ for i in range(4):
|
|
|
+ size_buttons_can_use[1].send_keys(Keys.BACKSPACE)
|
|
|
+ size_buttons_can_use[1].send_keys('100')
|
|
|
+
|
|
|
+ def set_movie(self):
|
|
|
+ # 设置视频
|
|
|
pass
|
|
|
|
|
|
- def set_set_text_button(self):
|
|
|
+ def set_text_button(self):
|
|
|
# 设置图文按钮
|
|
|
pass
|
|
|
|
|
@@ -392,9 +606,12 @@ class CreateAd:
|
|
|
pass
|
|
|
|
|
|
def get_layout(self):
|
|
|
+ # TODO:设置重试机制,然后错误后试错几次,查看是否成功
|
|
|
+
|
|
|
# 得到编排
|
|
|
|
|
|
- layout = {-1: {'page': '/usr/share/wallpapers/deepin/Beach_by_Samuel_Scrimshaw.jpg'},
|
|
|
+ layout = {-2: {'bc_color': True},
|
|
|
+ -1: {'page': '/usr/share/wallpapers/deepin/Beach_by_Samuel_Scrimshaw.jpg'},
|
|
|
0: {'title': '这是标题'},
|
|
|
1: {'content': '这是文本'},
|
|
|
2: {'follow_button': 1},
|
|
@@ -413,28 +630,36 @@ class CreateAd:
|
|
|
0: {'page': '/usr/share/wallpapers/deepin/Beach_by_Samuel_Scrimshaw.jpg'}
|
|
|
}
|
|
|
layout = {
|
|
|
- -1: {'page': '/usr/share/wallpapers/deepin/Reflection_of_the_Kanas_Lake_by_Wang_Jinyu.jpg'},
|
|
|
- 0: {'page': '/usr/share/wallpapers/deepin/Reflection_of_the_Kanas_Lake_by_Wang_Jinyu.jpg'},
|
|
|
- 1: {'page': '/usr/share/wallpapers/deepin/Beach_by_Samuel_Scrimshaw.jpg'},
|
|
|
- 2: {'page': '/usr/share/wallpapers/deepin/The_Gongga_Mountain_by_wangjinyu.jpg'},
|
|
|
+ -2: {'bc_color': True},
|
|
|
+ -1: {'movie': '/home/cxyu/Downloads/老奶奶.mp4'},
|
|
|
+ 0: {'title': '第一章'},
|
|
|
+ 1: {'content': 'asdfasdf'},
|
|
|
+ 2: {'follow_button': 1},
|
|
|
3: {'page': '/usr/share/wallpapers/deepin/Reflection_of_the_Kanas_Lake_by_Wang_Jinyu.jpg'},
|
|
|
-
|
|
|
+ 4: {'title': '第二章'},
|
|
|
+ 5: {'content': 'asdfadsfasdfasd'},
|
|
|
+ 6: {'follow_button': 2},
|
|
|
+ 7: {'follow_button': 3},
|
|
|
}
|
|
|
|
|
|
# self.send_file_alone(layout)
|
|
|
self.set_head_assemb(layout[-1])
|
|
|
- for _ in range(max(layout.keys())):
|
|
|
+ if -2 in layout.keys():
|
|
|
+ self.set_background_color()
|
|
|
+
|
|
|
+ for _ in range(max(layout.keys()) + 1):
|
|
|
info = layout[_]
|
|
|
info_key = list(info.keys())[0]
|
|
|
info_v = info[info_key]
|
|
|
if info_key == 'page':
|
|
|
self.set_page(info_v)
|
|
|
if info_key == 'title':
|
|
|
- self.set_page(info_v)
|
|
|
+ self.set_title(info_v)
|
|
|
if info_key == 'content':
|
|
|
self.set_content(info_v)
|
|
|
if info_key == 'follow_button':
|
|
|
self.set_follow_button(info_v)
|
|
|
+ time.sleep(100)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|