Skip to content

Instantly share code, notes, and snippets.

@isratmir
Last active April 1, 2016 13:02
Show Gist options
  • Save isratmir/c2828881aff4afccabf8 to your computer and use it in GitHub Desktop.
Save isratmir/c2828881aff4afccabf8 to your computer and use it in GitHub Desktop.
require 'mechanize'
require 'logger'
website = ARGV[0]
uname = ARGV[1]
upass = ARGV[2]
agent = Mechanize.new { |agent|
agent.open_timeout = 6
agent.read_timeout = 6
}
agent.log = Logger.new 'mechanize.log'
agent.user_agent_alias = 'Mac Safari'
site = agent.get website
login_page = site.link_with(text: 'Вход').click
login_form = login_page.form
ufield = login_form.field_with(name: "UserName")
pfield = login_form.field_with(name: "PassWord")
ufield.value = uname
pfield.value = upass
home = login_form.submit
post_page = home.link_with(href: website + '&from_login=1').click
#delLink = post_page.link_with(text: 'Удалить').href.gsub(/(javascript:delete_post\('|'\))/, '')
delLink = post_page.link_with(:href => /javascript:delete_post/).href.gsub(/(javascript:delete_post\('|'\))/, '')
res_page = agent.get delLink
post = res_page.link_with(text: "Или нажмите сюда, если не хотите ждать").click
replierForm = post.form('REPLIER')
replierForm.Post = 'up'
agent.submit(replierForm, replierForm.buttons.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment