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 #点击 ...
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 ...
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
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 ...
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)