每天要手工重发N多条的销售信息麻烦,我想用watir来实现自动发布。(当然阿里有工具不过是要钱的)
代码如下:
# the Watir controller
require "watir"
require "win32ole"
# set a variablehttp://china.alibaba.com/offer/manage.htm?tracelog=myali_menu_manageoffer
test_site = "http://china.alibaba.com/offer/manage.htm?tracelog=myali_menu_manageoffer"
content = ""
#open the IE browser
ie = Watir::IE.new
def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
#
# Do forever - assumes popups could occur anywhere/anytime in your application.
loop do
# Look for window with given title. Give up after 1 second.
ret = autoit.WinWait('Microsoft Internet Explorer', '', 1)
#ret = WinActivate("Microsoft Internet Explorer", "")
autoit.ControlClick("Microsoft Internet Explorer", "", "[CLASS:Button; INSTANCE:1]", 2)
#强行点击,以使其获得focus
puts(ret)
#
# If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).
if (ret==1) then autoit.Send("{Enter}") end
#
# Take a rest to avoid chewing up cycles and give another thread a go.
# Then resume the loop.
sleep(3)
end
end
RecordNum = 0 #发布的信息条数
while (RecordNum<31)
ie.goto test_site
puts " Step 1: click resend" #点击重发
ie.image(:src,"http://i01.c.aliimg.com/images/cn/market/myalibaba/word3a_nor.gif" ).click_no_wait
sleep(10)
$popup = Thread.new { check_for_popups } # start popup handler
at_exit { Thread.kill($popup) }
RecordNum=RecordNum+1
end
ie.goto test_site
此程序可以实现发布
但还有如下问题,希望大家指点:
1、点击“重发”前面三四条记录运行的比较快,后来运行会越来越慢。
2、目前用变量RecordNum 来实现发布的条数,要改进至是否存在“重发”按钮来循环。