Tips
- Puts Mechanic: AGENT_ALIASES can print out all available user_agent
- Puts mechanic.
instance_methods(false)
Output all methods of the Mechanism module
- Puts mechanic. instance_methods () Outputs all methods of the mechanic module and the functions of the inherited classes.
Recommended reading
Official documentation
Many machize Examples
Simulate Google Search
Analyze and batch download School Intranet album photos using the mechanism
Mechanical ize user manual Chinese Version
Machize User Manual (English version)
Some common methods to simulate natural web page interaction by using the mechanism
In Ruby, web page capturing is usually implemented using the mechanism, which is very simple to use.
Install
sudo gem install mechanize
Capture webpages
require == agent.get()
Simulate click events
page = agent.page.link_with(:text => ).click
Simulate form submission
google_form = page.form(] = =
Analysis page. The mechanism uses nokogiri to parse the webpage. Therefore, you can refer to the nokogiri document.
table = page.search(=
Note: If you need to log on to the webpage first, you can log on to the website first, log on to the JSESSIONID, and assign it to the agent.
cookie = Mechanize::Cookie.new(, = =
If you need to save the webpage, use. save_as (or save, I have not tried it). For example:
agent.get().save_as
Reprinted from: http://www.cnblogs.com/Stoned/archive/2012/02/23/2364389.html