V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
314x
V2EX  ›  问与答

有什么办法能弄到v2ex里面所有用户的头像图片?

  •  
  •   314x · 2013-12-30 21:37:07 +08:00 · 3672 次点击
    这是一个创建于 3790 天前的主题,其中的信息可能已经有所发展或是发生改变。
    求支招
    20 条回复    1970-01-01 08:00:00 +08:00
    ovear
        1
    ovear  
       2013-12-30 21:57:48 +08:00
    我说一个思路吧,虽然不是所有的头像,但是大部分还是没问题的。

    搜索引擎site:http://v2ex.com/member
    然后分析下内容就可以拿到头像。当然更快捷的方法是分析头像连接的生成。。
    shiny
        2
    shiny  
       2013-12-30 22:03:56 +08:00   ❤️ 9
    简单,观察下 url 规律,举例:
    我的 id 是5670,md5 hash下,8909a6e385b0fbc1f3885c00ae838de7
    把结果的前8位及用户 id 代入头像的 URL。
    http://cdn.v2ex.com/avatar/8909/a6e3/5670_large.png

    然后循环 uid 就可以得到所有头像了。
    Tink
        3
    Tink  
       2013-12-30 22:36:37 +08:00
    @shiny 赞啊!牛逼
    lijinma
        4
    lijinma  
       2013-12-30 22:48:46 +08:00
    @shiny 厉害。
    niseter
        5
    niseter  
       2013-12-31 00:19:55 +08:00 via Android
    @shiny 厉害啊
    Mutoo
        6
    Mutoo  
       2013-12-31 01:04:57 +08:00
    哈哈,果断加盐。
    fangzhzh
        7
    fangzhzh  
       2013-12-31 08:15:23 +08:00
    @shiny 头像存储的代码就是你写的吧? ╮(╯▽╰)╭
    lei2xiao
        8
    lei2xiao  
       2013-12-31 09:20:07 +08:00
    @shiny 厉害,点赞。
    isayme
        9
    isayme  
       2013-12-31 12:49:23 +08:00   ❤️ 1
    按照
    @shiny 的方法写了简单python脚本:https://gist.github.com/isayme/8192703
    shiny
        10
    shiny  
       2013-12-31 14:00:30 +08:00
    @fangzhzh 呃,真不是我写的,只不过储存头像的时候考虑的因素都是差不多的,如果是我也会用差不多的方法来写。
    kevinroot
        11
    kevinroot  
       2013-12-31 14:04:39 +08:00 via iPhone
    这个肯定有算法嘛,不然v2ex自己也没法取。
    kevinroot
        12
    kevinroot  
       2013-12-31 14:06:21 +08:00 via iPhone
    现在问题是所有uid去哪里取?你有库?
    314x
        13
    314x  
    OP
       2013-12-31 14:16:24 +08:00
    @isayme 能把你抓到的头像打包分享一下么
    wherefor
        14
    wherefor  
       2013-12-31 14:26:27 +08:00
    @shiny
    能解惑下
    为什么是取uid md5的前八位?md5算法有会保证前八位冲突最小吗?
    shiny
        15
    shiny  
       2013-12-31 14:58:32 +08:00   ❤️ 1
    @kevinroot uid 不是自增的么,从1到最新注册的用户的 uid,跳过404嘛。

    @wherefor 因为头像不能放一个文件夹里,需要用 uid 为变量来分割到不同文件夹(也可以用其他变量,但是会把事情搞复杂)。hash 下是其中一种办法,取八位是等于把头像分割到二级目录里,每个文件夹里有数万个文件/文件夹,同时路径也不会太长。
    其他还有比如 uid / 1000 这类分割方法。

    头像也不是什么敏感数据,不需要做太多防范吧。
    kevinroot
        16
    kevinroot  
       2013-12-31 15:21:36 +08:00
    @shiny 有道理O(∩_∩)O哈哈~
    fdsfsdfsdf3334
        17
    fdsfsdfsdf3334  
       2013-12-31 16:17:04 +08:00
    帅啊
    mahone3297
        18
    mahone3297  
       2013-12-31 18:40:10 +08:00
    辛苦写了一下午,贡献给大家。。。不知道怎么贴代码
    <code>
    require 'net/http'
    require 'digest'

    desc "fetch avatar from http://www.v2ex.com/"
    task :fetch_avatar do
    prefix = 'images/'

    (1..50000).each do |idx|
    puts "process id = " + idx.to_s + "\n"

    md5 = Digest::MD5.hexdigest(idx.to_s)
    remote_dir = md5[0,4] + '/' + md5[4,4] + '/'
    local_dir = prefix + remote_dir
    FileUtils.mkdir_p local_dir if ! Dir.exists? local_dir

    remote_filename = remote_dir + idx.to_s + '_large.png'
    local_filename = prefix + remote_filename
    next if File.exists? local_filename

    url = 'http://cdn.v2ex.com/avatar/' + remote_filename
    IO.binwrite(local_filename, Net::HTTP.get(URI(url)))
    end
    end
    </code>
    shiny
        19
    shiny  
       2014-01-01 00:07:05 +08:00
    @mahone3297 我也很喜欢 Ruby。在 v2ex 贴代码只要贴 gist 的 URL 就可以了。
    isayme
        20
    isayme  
       2014-01-01 15:52:12 +08:00   ❤️ 1
    @314x 哥,你自己执行下脚本就好了。。。 我更新了下,处理了404的那些。。。
    PS:图片下载在脚本所在的目录。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1362 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:50 · PVG 01:50 · LAX 10:50 · JFK 13:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.