Watir给Amazon.cn充礼品卡

写个脚本去尝试不花钱给自己的Amazon.cn账号充礼品卡,碰碰运气。

#encoding: UTF-8                                          #添加这一行才可以处理中文
require 'rubygems'                                        #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

def randCharOfLength(len)                                 #产生随机任意长度的数
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    str = ""
    1.upto(len) {|i| str << chars[rand(chars.size-1)]}
    return str
end
b = Watir::Browser.new(:firefox ...
more ...

Watir获得sedo网站上指定后缀域名列表

作为一个’米农‘,sedo.com网站上面的信息很有价值。sedo.com是全球最大的域名交易网站。下面我写的这个脚本是用来取得sedo上面指定后缀(_如.asia)的所有域名列表。

#encoding: UTF-8                                          #添加这一行才可以处理中文
require 'rubygems'                                        #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

#b=Watir::Browser.new(:firefox, {:profile => 'default'})
output =File.new("sedo_asia.txt",'w:UTF-8') 
def pre_work()
  $b=Watir::Browser.new :ff
  $b.driver.manage.timeouts.implicit_wait ...
more ...

Watir登陆微博发布微博

#encoding: UTF-8                       #添加这一行才可以处理中文
require 'rubygems'                     #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

b = Watir::Browser.new(:firefox, {:profile => 'default'})
b.goto 'www.weibo.com'
b.text_field(:class,"W_input").focus
b.text_field(:class,"W_input").set 'your_weibo_email_account'
b.div(:class, "inp password").text_field(:type,"password").set 'your_weibo_password'
b.link(:class ...
more ...

Watir自动为优酷视频刷顶

很喜欢优酷上面的一个节目,想帮帮它早日升到排行榜怎么办?写个脚本好了。

#encoding: UTF-8                       #添加这一行才可以处理中文
require 'rubygems'                     #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

b = Watir::Browser.new(:firefox, {:profile => 'default'})
b.driver.manage.timeouts.implicit_wait =60                  #默认的等待页面加载30秒若还未加载完成则会跑出timeout异常,这里可以修改成60秒
b.goto 'http://v.youku.com/v_show/id_XNTE5MTY3NzI4.html'    #假设我现在要为这个视频刷“顶”
for i in 1..100                                             #假设我这里要"顶 ...
more ...

Ruby分割文件

自己小试的ruby程序,用于将一个dictionary.txt分割成多个小一点的子文件,不然每次都操作dictionary.txt显得很笨重。想把dictionary.txt按照字母首a~z,每个首字母再按长度分为长度为1~3的比如a_1to3.txt,长度为4的a_4.txt,长度为5的a_5.txt,长度为6的a_6.txt,长度为7的a_7.txt,长度为8的a_8.txt,以及长度大于8的others。这样,dictionary.txt最后被分割成了6x26+1=157个子文件,就不会像处理dictionary.txt那样笨重了,毕竟CPU有限。
为啥wordpress里面粘贴代码都只有黑乎乎的一片呢,可爱的语法高亮在哪里?还是喜欢五颜六色的代码段啊,上图吧:
1

只需10秒左右,就生产了157个文件,a_1to3,a_4,a_5...b_1to3,b_4,b_5...z_1to3,z_4 ...

more ...

Watir重新连接路由器

有些网站对IP有所限制,如果你不想用代理IP的话,那么有一个看起来有点傻但却很简单的办法可以起到更换IP的效果——将路由器断线重连。因为家用宽带路由器的IP基本上是由运营商动态分配的,所以你只要登陆路由器,点击断线,等内网发送数据包请求至外网的时候,路由器重新连接上,IP也随之改变了。这方法虽然笨,但也实用。下面是用Watir脚本实现的,仅供参考。

#encoding: UTF-8                                          #添加这一行才可以处理中文
require 'rubygems'                                        #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

b=Watir::Browser.start 'http://admin:admin@192.168.1.1'   #用此方法可以避开用户密码登陆框 用户名密码这里都是admin
b.frame(:name,"bottomLeftFrame").link(:id,'a0').click     #点击 ...
more ...

Watir收集最快的代理服务器ip列表

这个脚本所做的事情是从www.cnproxy.com网站上取得最新的10页代理服务器的ip,将它们写到proxy_ip_list.txt文本文件中去。包括每一个代理服务器的响应时间。

#encoding: UTF-8                       #添加这一行才可以处理中文
require 'rubygems'                     #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

time1=Time.now
proxy_ip_lists=File.new("proxy_ip_lists.txt",'w')
def char2int(str)
    for i in 0.. str.length-1
      if str[i]=='z' then str[i]='3'
      elsif str[i ...
more ...

Watir设置代理

#encoding: UTF-8                       #添加这一行才可以处理中文
require 'rubygems'                     #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => 'my.proxy.com:8080', :ssl => 'my.proxy.com:8080'
browser = Watir::Browser.new :firefox, :profile => profile
more ...

Watir登陆谷歌搜索关键字

#encoding: UTF-8    #添加这一行才可以处理中文
require 'rubygems'  #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

begin
 Timeout::timeout(10)  do |timeout_length|  #在国内,google经常被墙导致连接超时
  b.goto 'http://www.google.com.hk/webhp?hl=zh-CN&sourceid=cnhp'
 end
rescue Timeout::Error => e
   puts "page is not completed loaded, program will go on procesing ...
more ...

Watir登陆163邮箱

#encoding: UTF-8    #添加这一行才可以处理中文
require 'rubygems'  #gem install xxx --no-ri --no-rdoc
require 'watir-webdriver'

b= Watir::Browser.new(:firefox, {:profile => 'default'})
b.goto  "http://mail.163.com/"
b.text_field(:name, "username").clear
b.text_field(:name, "username").set("your_username")
b.text_field(:name, "password").set("your_password")
b.button(:type, "submit").click
sleep(3) 
more ...