selenium自动化脚本将语雀和MindMaster的脑图转移到飞书

2022年05月06日 效率提升, 计算机与互联网 暂无评论 阅读1,985 次

之前脑图笔记分散在MindMaster和语雀上,逐渐积累了上千节点的脑图,越来越希望能在一个软件上统一管理。

同时MindMaster对笔记分享支持不太友好,语雀分享也需要开通会员。

综合考虑选择统一转移到飞书上,既能分享,导入导出的支持也相对比较完善。

软件本身肯定不支持这样的功能了,还好都支持导出为excel文件。飞书也支持通过文本再转为脑图

设计方案通过读取excel,然后通过selenium的方式输出文本格式脑图到飞书。

MindMaster和语雀导出的excel格式有点区别分别写了脚本。

注意脑图节点里不要有大括号{}和@字符,不然导入飞书可能会有问题。

代码比较简单整理如下

首先通过selenium打开chrome再打开飞书的脑图页面。

if __name__ == '__main__':
option=Options()
option.binary_location='chrome便携.exe'
option.add_argument(r'--user-data-dir=Data')
option.add_argument(r'--remote-debugging-port=9222')
# 步骤2获取到的--profile-directory值
option.add_argument("--profile-directory=Profile 2")
s=Service("chromedriver.exe")
driver = webdriver.Chrome(service=s,options=option)
driver.get('https://www.baidu.com')
print("结束")

然后运行mindmaster导入飞书的脚本

option = Options()
option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s, options=option)


def writ():
data = xlrd.open_workbook(r'ndk.xls')
table = data.sheets()[0]
rows = table.nrows
columns=table.ncols
for num in range(rows):
if(num==0):
continue
for column in range(columns):
onedata = table.cell(num, column)
if(onedata.ctype!=0):
for k in range(column):
driver.switch_to.active_element.send_keys(Keys.TAB)
driver.switch_to.active_element.send_keys(onedata.value.strip())
driver.switch_to.active_element.send_keys(Keys.ENTER)
for k in range(column):
driver.switch_to.active_element.send_keys(Keys.SHIFT,Keys.TAB)

if __name__ == '__main__':
writ()
print("结束")


最后是语雀导入飞书的脚本
option = Options()
option.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s, options=option)

tempempty = {};
def writ():
file_handle = open('1.txt', mode='a+',encoding='utf-8')
data = xlrd.open_workbook(r'androidyuque.xls')
table = data.sheets()[0]
rows = table.nrows
columns=table.ncols
for num in range(rows):
for column in range(columns):
onedata = table.cell(num, column)
celldata=onedata.value.strip()
if(onedata.ctype!=0 and (column in tempempty and tempempty[column]!=celldata) or column not in tempempty):
for k in range(column):
driver.switch_to.active_element.send_keys(Keys.TAB)
driver.switch_to.active_element.send_keys(onedata.value.strip())
driver.switch_to.active_element.send_keys(Keys.ENTER)
for k in range(column):
driver.switch_to.active_element.send_keys(Keys.SHIFT,Keys.TAB)
tempempty[column] = celldata


if __name__ == '__main__':
writ()
print("结束")

给我留言

切换注册

登录

忘记密码 ?

切换登录

注册