一个脚本×关键词“百度说吧”你懂的_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > 一个脚本×关键词“百度说吧”你懂的

一个脚本×关键词“百度说吧”你懂的

 2010/9/19 23:12:44  xhanxhanxhan  http://blogs.javaeye.com  我要评论(0)
  • 摘要:很久没更新但还是陆续有访问者,有点而不安。发个和百度最近的说吧有点儿关系的脚本。你懂得。#!/usr/bin/envruby#@autherxhan#@datesep19,2010#@websitehttp://ixhan.comrequire'net/http'require'net/https'require'rubygems'require'json'deffollow!#puts"usage:from_idto_id(notincluded)"andreturnunlessARGV
  • 标签:一个脚本×关键词 百度说吧

很久没更新但还是陆续有访问者,有点而不安。

发个和百度最近的说吧有点儿关系的脚本

你懂得。

?

#!/usr/bin/env ruby
#  @auther xhan
#  @date sep19, 2010
#  @website http://ixhan.com

require 'net/http'
require 'net/https'
require 'rubygems'
require 'json'

def follow!
  # puts "usage: from_id to_id(not included)" and return  unless ARGV.count == 2  #why not works?
  if ARGV.count != 2
    puts "usage: from_id to_id(not included)" 
    return
  end
  
  from,to = ARGV
  from,to = from.to_i,to = to.to_i - 1  
  total = to - from + 1
  
  puts "wrong argus" and return if total < 0
  puts "=== Task starts at duration [#{from},#{to}]"  
  
  
  http = Net::HTTP.new('t.baidu.com')
  path = '/follow/setfollow?rn=56.392819142620596'
  headers = {
    'Cookie' => "YOUR COOKIES HERE",
    'Referer' => 'http://t.baidu.com/',
    'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
    # X-Request-By	baidu.ajax
  }
    
  
  # {"status":-1,"msg":"已经关注了"}
  # {"status":-1,"msg":"该用户不存在或者帐号异常"}
  # status = 1 => success
  successed = 0
  start_time = Time.now

  (from..to).each do |uid|
    data = "&uid=#{uid}&t=t"  
    resp, data = http.post(path, data, headers)

    # puts 'Code = ' + resp.code + '   Msg = ' + resp.message  
    # resp.each {|key, val| puts key + ' = ' + val}
    puts "uid #{uid}: data:#{data}"
    json = JSON.parse(data)
    successed += 1 if json['status'].to_i == 1
    
  end

  end_time = Time.now
  puts "=== Task finished =============="
  puts "time: #{end_time-start_time}"
  puts "followed:#{successed}"
  puts "failed:#{total - successed}"
  puts "================================"
  
end


follow!

?使用说明

http://gist.github.com/586555

?

不过好久没写ruby有个问题请教下。

?

为什么

  # puts "usage: from_id to_id(not included)" and return  unless ARGV.count == 2  #why not works?
这句话的 return 不管用?
发表评论
用户名: 匿名