一键自动化博客发布工具,用过的人都说好(infoq篇)
使用一键自动化博客发布工具blog-auto-publishing-tools把博客发布到infoq上。
最后更新于
这有帮助吗?
使用一键自动化博客发布工具blog-auto-publishing-tools把博客发布到infoq上。
最后更新于
这有帮助吗?
这有帮助吗?
# 上传封面
if 'image' in front_matter and front_matter['image']:
file_input = driver.find_element(By.XPATH, "//input[@type='file']")
# 文件上传不支持远程文件上传,所以需要把图片下载到本地
file_input.send_keys(download_image(front_matter['image']))
time.sleep(2) # 文章标题
title = driver.find_element(By.XPATH, '//input[@placeholder="请输入标题"]')
title.clear()
if 'title' in front_matter['title'] and front_matter['title']:
title.send_keys(front_matter['title'])
else:
title.send_keys(common_config['title'])
time.sleep(2) # 等待3秒# 文章内容 markdown版本
file_content = read_file_with_footer(common_config['content'])
# 用的是CodeMirror,不能用元素赋值的方法,所以我们使用拷贝的方法
cmd_ctrl = Keys.COMMAND if sys.platform == 'darwin' else Keys.CONTROL
# 将要粘贴的文本内容复制到剪贴板
pyperclip.copy(file_content)
action_chains = webdriver.ActionChains(driver)
# tab
action_chains.key_down(Keys.TAB).key_up(Keys.TAB).perform()
time.sleep(2)
# 模拟实际的粘贴操作
action_chains.key_down(cmd_ctrl).send_keys('v').key_up(cmd_ctrl).perform()
time.sleep(3) # 等待3秒 # 发布文章
send_button = driver.find_element(By.XPATH, '//div[contains(@class, "submit-btn")]')
send_button.click()
time.sleep(2) if summary:
summary_input = driver.find_element(By.XPATH, '//div[@class="summary"]/textarea')
summary_input.clear()
summary_input.send_keys(summary)
time.sleep(2) if tags:
for tag in tags:
tag_input = driver.find_element(By.XPATH, '//div[@class="search-tag"]//input')
tag_input.send_keys(tag)
time.sleep(1)
tag_input.send_keys(Keys.ENTER) if auto_publish:
publish_button = driver.find_element(By.XPATH, '//div[@class="dialog-footer-buttons"]/div[contains(text(),"确定")]')
publish_button.click()