在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
require "watir"
require 'hpricot' require 'open-uri' ie = Watir::IE.new def get_ids_and_names(url) doc = Hpricot(url) names = [] ids = [] doc.search("strong/a").each do |a| ids << $1 if a.to_s.match(/id=(\d+)/) names << Hpricot(a.to_s).search("a").inner_html.strip end return ids,names end username = "[email protected]" userpass = "***" ie.goto "http://www.xiaonei.com/" ie.text_field(:name, "email").clear ie.text_field(:name, "email").set("#{username}") ie.text_field(:name, "password").set("#{userpass}") ie.button(:id, "login").click 0.upto(10) do |p| query = "%E5%AE%81%E5%A4%8F" #把关键字在谷歌上转换下就好了 url = "http://browse.xiaonei.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 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论