获取gitee上某个组织所有仓库的介绍

获取gitee上某个组织所有仓库的介绍

背景: 想用LLM总结一下ascend的开源项目
步骤:
1.用下面的脚本抓取所有项目介绍
2.合并文件
3.上传到智谱长文档解读
4.提问

代码(由GPT-4O自动生成)

import requests
from bs4 import BeautifulSoup
import html2text

def download_and_extract_links(url):
    # 下载网页内容
    response = requests.get(url)
    if response.status_code != 200:
        raise ValueError(f"无法访问网页: {url}")
    
    # 解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 提取所有 <a class="repository"> 标签中的 href 属性
    links = []
    for a_tag in soup.find_all('a', class_='repository'):    
        href = a_tag.get('href')
        if href:
            links.append((a_tag.text,f"https://gitee.com/{href}"))
    
    return links

def download_and_save_markdown_content(url, file_path):
    # 下载网页内容
    response = requests.get(url)
    if response.status_code != 200:
        raise ValueError(f"无法访问网页: {url}")

    # 解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 查找指定 <div class="file_content markdown-body"> 标签
    div_tag = soup.find('div', class_='file_content markdown-body')
    if div_tag is None:
        raise ValueError(f"网页中未找到 <div class='file_content markdown-body'> 标签")

    # 获取这个 div 标签中的 HTML 内容
    html_content = div_tag.decode_contents()

    # 将 HTML 内容转换为 Markdown
    markdown_content = html2text.html2text(html_content)

    # 将 Markdown 内容保存到文件
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(markdown_content)

for i in range(1,4):
    url = f'https://gitee.com/organizations/ascend/projects?page={i}'
    links = download_and_extract_links(url)
    for (title,link) in links:
        print(title,link)
        download_and_save_markdown_content(link,f"docs/{title}.md")

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-07 09:38:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-07 09:38:05       101 阅读
  3. 在Django里面运行非项目文件

    2024-06-07 09:38:05       82 阅读
  4. Python语言-面向对象

    2024-06-07 09:38:05       91 阅读

热门阅读

  1. 系统研发安全漏洞

    2024-06-07 09:38:05       27 阅读
  2. vue el-dialog封装成子组件(组件化)

    2024-06-07 09:38:05       26 阅读
  3. react-intl国际化在项目中的使用

    2024-06-07 09:38:05       29 阅读
  4. 浅谈人机交互

    2024-06-07 09:38:05       25 阅读
  5. 人机交互中的阴差阳错

    2024-06-07 09:38:05       25 阅读
  6. 解决nginx无法获取带下划线的header值

    2024-06-07 09:38:05       31 阅读
  7. 单双目视频转图片

    2024-06-07 09:38:05       24 阅读
  8. 常见排序算法,快排,希尔,归并,堆排

    2024-06-07 09:38:05       23 阅读
  9. Elasticsearch简介

    2024-06-07 09:38:05       27 阅读
  10. scss sass是什么?vue环境安装sass报错

    2024-06-07 09:38:05       24 阅读
  11. GUI guider 常用函数解析

    2024-06-07 09:38:05       19 阅读
  12. 洛谷 P3870 [TJOI2009] 开关 题解 线段树

    2024-06-07 09:38:05       29 阅读