Convert Feishu documents to MD in batches using Python

Note: Feishu is an online document platform. This article introduces how to use a Python program to batch convert Feishu documents into MD documents and download them locally;

Copy address

First, copy the URL of the document. This requires copying one by one, but it is the most workload step;

Insert image description here

as follows:

Insert image description here

Convert

To convert Feishu to Markdown, there is a tool on GitHub that can convert Feishu documents to Markdown online and generate a compressed package (.zip) locally.

Insert image description here

This tool provides an online version ;

Insert image description here

Copy the previous document address in Feishu here and click DOWNLOADon it.

Insert image description here

analyze

We can use the Python program to convert the Feishu document that needs to be converted to MarkDown, and use the Python program to loop to access this address.

First, analyze the previous conversion attack and DOWNLOADthe request link sent after clicking, as follows:

Insert image description here

Through analysis, it can be seen that the format of the address is like this;

Insert image description here

Format:

https://feishu2md.onrender.com/download?url=https%3A%2F%2Fqwek6s2dw90.feishu.cn%2Fwiki%2F + 文档地址码 + %3Fchunked%3Dfalse

coding

This is easy to handle, start coding, as follows:

import requests

# 飞书中的文档地址码
doc_list = [
    "XXXXXXXXXXXXXXXXXXBn9b",
    "XXXXXXXXXXXXXXXXXXTnBg",
    "XXXXXXXXXXXXXXXXXX5nFL",
    "XXXXXXXXXXXXXXXXXXxnUs",
    "XXXXXXXXXXXXXXXXXXOnGf",
    "XXXXXXXXXXXXXXXXXXVnxb",
    "XXXXXXXXXXXXXXXXXXgnhc",
    "XXXXXXXXXXXXXXXXXXVnwc",
    "XXXXXXXXXXXXXXXXXXAnIg",
    "XXXXXXXXXXXXXXXXXXbnis",
    "XXXXXXXXXXXXXXXXXXnnDg",
    "XXXXXXXXXXXXXXXXXXJnDf",
    "XXXXXXXXXXXXXXXXXXmnSd",
    "XXXXXXXXXXXXXXXXXXEnlh",
    "XXXXXXXXXXXXXXXXXXEnJg",
    "XXXXXXXXXXXXXXXXXXjnBg",
]

# 遍历文档并转换
for index, value in enumerate(doc_list):

    # 拼接URL
    url = (
        "https://feishu2md.onrender.com/download?url=https%3A%2F%2Fqwek6s2dw90.feishu.cn%2Fwiki%2F"
        + value
        + "%3Fchunked%3Dfalse"
    )

    # 发送请求
    response = requests.get(url, stream=True)

    # 写入到本地
    if response.status_code == 200:
        with open(r'C:\Users\10765\Desktop\markdown'+ '\\' + str(index) + ".zip", "wb") as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print("文件下载完成!")
    else:
        print("文件下载失败,状态码:", response.status_code)

Set the path to the desktop, file name as index, start the program, and test. The download speed depends on the size of the Feige document. I downloaded more than a dozen documents in about ten minutes;

Insert image description here

The compressed package contains documents and static resources (pictures);

Insert image description here

In this way, the steps to batch convert Feishu documents to MD documents are completed;

Guess you like

Origin blog.csdn.net/qq_42108331/article/details/132405771