# 获取所有文章链接 article_url_list = [] for item in Repo_Result: if item['type'] == "Book": if item['name'] == '博客文章-公开': pass else: break repo_id = item['id'] url_docs = 'https://www.yuque.com/api/v2/repos/' + str(repo_id) + '/docs' Doc_Result = requests.get(url_docs, headers=header).json()['data']
for ii in Doc_Result: slug = ii['slug'] url = f"https://www.yuque.com/api/v2/repos/{repo_id}/docs/{slug}" article_url_list.append(url) info = {"header":header, "Repo_Result":Repo_Result, "article_url_list":article_url_list } return info
for url in article_url_list: count = count + 1 single_doc = requests.get(url, headers=header).json() article_title = single_doc["data"]["title"].translate(table) print(f"{count}/{file_num}: {article_title}") article_body = single_doc["data"]["body"] pattern = r'!\[.*?\]\(.*?\)' matches = re.findall(pattern, article_body) for ii in matches: PIC_Url.append(article_title+": "+ii)
return PIC_Url
if __name__ == "__main__": yuque_token = "***" info = login_get_doc(yuque_token) PIC_Url = get_pic_url(info) print(PIC_Url)
# 将列表写入txt文件 withopen('PIC_Url.txt', 'w', encoding='utf-8') as file: for link in PIC_Url: if'https://mypic2016.oss-cn-beijing.aliyuncs.com'notin link: file.write(link + '\n')