mechanize useage

Mechanize (http://mechanize.rubyforge.org/GUIDE_rdoc.html#label-Getting+Started+With+Mechanize)

example

baidu search:

1
2
3
4
5
6
require  "mechanize"
agent = Mechanize.new
page = agent.get("http://www.baidu.com")
result_page = page.form_with(name: "f") do |form|
form["wd"] = "ruby"
end.submit

login cms:

1
2
3
4
5
6
7
8
9
10
11
12
agent = Mechanize.new
page = agent.get("http://cms.stage.lanshizi.com/admin/login")
login_form = page.form_with(action: "/admin/login") do |form|
  form["admin_user[username]"] = "sa"
  form["admin_user[password]"] = "sa"
end
cms_page = login_form.submit
if message = cms_page.at(".flash_alert")
  p message.text
else
  p cms_page
end

captcha 破解

  • 破解破解验证码 captcha
  • 破解同个客户端获取captcha图片并且保存
  • 破解RTesseract 解释图片

code:

1
2
3
4
5
6
7
@agent.get(@captcha_url).save("captcha.jpg")
@app_list_page = @agent.get(@login_url).form_with(id: "loginForm") do |f|
f.action = "/accounts/signin/"
  f["username"] = @username
  f["password"] = @password
  f["captcha"] = RTesseract.new("captcha.jpg").to_s.strip
end.click_button

定制我们自己的 JQuery 插件

### 介绍---一直来使用过的 JQuery 插件很多,也写过一些 JQuery 库的扩展。然而要真正了解插件如何扩展 JQuery 库需要对 JavaScript prototype 属性有一些基本的了解。虽然说不直接使用,但是 JavaScript prototype...… Continue reading

HTML INPUT TYPE

Published on July 26, 2015

HTTP 信封里的文档

Published on July 16, 2015