0.upto(10) do|p| query ="%E5%AE%81%E5%A4%8F"#把关键字在谷歌上转换下就好了 url =http://browse.renren.com/os.do?curpage=#{p}&k=&q=#{query}&n=-1 ie.goto(url) sleep(5) i=0 10.times do begin @ids,@names =get_ids_and_names(ie.html) ie.link(:id,"addFriend#{@ids[i]}").click sleep(3) ie.text_field(:id,"addFriendMessage").set("hi,"+@names[i]) sleep(3) ie.button(:index=>1).click sleep(3) i +=1 rescue next end end end