V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
holajamc
V2EX  ›  Python

用 Python 写了一个 GitHub 的小爬虫,求指点~~~

  •  
  •   holajamc · 2016-09-21 17:55:33 +08:00 · 3710 次点击
    这是一个创建于 2784 天前的主题,其中的信息可能已经有所发展或是发生改变。

    介绍

    本来打算写一个 GitHub_Following 的爬虫,结果造了一个轮子,写了抓登录用户的 Star,Following,Follower,Repo 信息,说不定以后能用到哈哈

    地址

    github_spider

    说明

    只是一个测试小样, todo 很多实在不好意思写了~ 用了 requests 和 bs4 ,先安装这两个库然后再用 使用方法 python demo.py 然后在控制台输入邮箱和密码,根据自己需求改一下就好了,提供了以下的方法:

    • user_followers()用户关注
    • user_following()用户粉丝
    • user_index()用户主页
    • user_repositories()用户仓库
    • user_star()用户星星

    flag

    flag=True 表示代码自己加工输出信息,以 json 形式输出,反之则返回网页源码

    小样

    用 user_repositories()的返回举个例子,根据是 source 还是 fork 分类

    {
      "sources": [
        {
          "repositories_url": "https://github.com//HolaJam/github_spider", 
          "repositories_name": "github_spider", 
          "repositories_programmingLanguage": "Python", 
          "repositories_description": "一个简单的 GitHub 爬虫 A Simple Spider for GitHub"
        }, 
        {
          "repositories_url": "https://github.com//HolaJam/luowang", 
          "repositories_name": "luowang", 
          "repositories_programmingLanguage": "Python", 
          "repositories_description": "You Can Get Wonderful Music."
        }, 
      ], 
      "forks": [
        {
          "repositories_url": "https://github.com//HolaJam/head-first-flask", 
          "repositories_name": "head-first-flask", 
          "repositories_programmingLanguage": "Null", 
          "repositories_description": "Introduction to Flask Web development."
        }, 
        {
          "repositories_url": "https://github.com//HolaJam/gitblogdoc", 
          "repositories_name": "gitblogdoc", 
          "repositories_programmingLanguage": "PHP", 
          "repositories_description": "gitblog 文档"
        }, 
        {
          "repositories_url": "https://github.com//HolaJam/ToughRADIUS", 
          "repositories_name": "ToughRADIUS", 
          "repositories_programmingLanguage": "JavaScript", 
          "repositories_description": "TOUGHRADIUS 是一个开源的 Radius 服务软件,支持标准 RADIUS 协议,提供完整的 AAA 实现。支持灵活的策略管理,支持各种主流接入设备并轻松扩展,具备丰富的计费策略支持。"
        }, 
        {
          "repositories_url": "https://github.com//HolaJam/MyPlatform", 
          "repositories_name": "MyPlatform", 
          "repositories_programmingLanguage": "Python", 
          "repositories_description": "文科生也会配的微信个人号后台, Content based wechat massive platform framework, what you need to do is only adding your articles in :)"
        }, 
        {
          "repositories_url": "https://github.com//HolaJam/Web-Crawler", 
          "repositories_name": "Web-Crawler", 
          "repositories_programmingLanguage": "Python", 
          "repositories_description": "是一种“自动化浏览网络”的程序,或者说是一种网络机器人。它们被广泛用于互联网搜索引擎或其他类似网站,以获取或更新这些网站的内容和检索方式。它们可以自动采集所有其能够访问到的页面内容,以供搜索引擎做进一步处理(分检整理下载的页面),而使得用户能更快的检索到他们需要的信息。"
        }, 
    }
    
    8 条回复    2016-09-21 19:27:04 +08:00
    tinyproxy
        1
    tinyproxy  
       2016-09-21 18:14:06 +08:00
    有个东西叫 Github API ,你抓的东西我看不出有啥 API 满足不了的东西。。。

    https://developer.github.com/v3/users/
    holajamc
        2
    holajamc  
    OP
       2016-09-21 18:15:58 +08:00 via Android
    @tinyproxy 啊原本打算做一个 github 用户关系的,结果做了一个这样的东西出来😂
    7sDream
        3
    7sDream  
       2016-09-21 18:18:15 +08:00   ❤️ 1
    虽然不该打击楼主……

    但是恕我直言, Github 有 API 的: https://developer.github.com/v3/

    用户资料: https://api.github.com/users/7sDream
    用户粉丝: https://api.github.com/users/7sDream/followers
    用户关注: https://api.github.com/users/7sDream/following
    用户仓库: https://api.github.com/users/7sDream/repos
    用户星星: https://api.github.com/users/7sDream/starred

    etc …… 能想到的基本都有了……
    7sDream
        4
    7sDream  
       2016-09-21 18:18:50 +08:00
    @7sDream 回晚了 =,=
    holajamc
        5
    holajamc  
    OP
       2016-09-21 18:21:20 +08:00 via Android
    @7sDream 啊我是知道的。。当时打算是做个用户关系出来的然后就做了这个例子😂回头来继续做
    linuxchild
        6
    linuxchild  
       2016-09-21 18:34:03 +08:00 via iPhone
    唔 开始以为楼主用的 github 的 api
    holajamc
        7
    holajamc  
    OP
       2016-09-21 18:34:58 +08:00 via Android
    @linuxchild 闭门造轮子哈哈😄
    devzero
        8
    devzero  
       2016-09-21 19:27:04 +08:00 via Android
    真.造轮子,话说如果抓到的话关系图楼主打算怎么呈现出来?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1141 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 18:26 · PVG 02:26 · LAX 11:26 · JFK 14:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.