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

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

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

你懂得。

 

#!/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 不管用?

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值