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

2013-12-30 21:37:07 +08:00
 314x
求支招
3684 次点击
所在节点    问与答
20 条回复
ovear
2013-12-30 21:57:48 +08:00
我说一个思路吧,虽然不是所有的头像,但是大部分还是没问题的。

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

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

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

头像也不是什么敏感数据,不需要做太多防范吧。
kevinroot
2013-12-31 15:21:36 +08:00
@shiny 有道理O(∩_∩)O哈哈~
fdsfsdfsdf3334
2013-12-31 16:17:04 +08:00
帅啊
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
2014-01-01 00:07:05 +08:00
@mahone3297 我也很喜欢 Ruby。在 v2ex 贴代码只要贴 gist 的 URL 就可以了。
isayme
2014-01-01 15:52:12 +08:00
@314x 哥,你自己执行下脚本就好了。。。 我更新了下,处理了404的那些。。。
PS:图片下载在脚本所在的目录。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/95092

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX