SlideShare a Scribd company logo
1 of 1
Download to read offline
The Agent                                                        Accessing page elements                                                      Forms
                                                              # The current page                                                    # Submitting a form without a button:
 require 'rubygems'                                                                                                                 form.submit
                                                              agent.page
 require 'mechanize'
                                                              # The HTML page content                                               # Submitting a form with the default button
 agent = WWW::Mechanize.new                                   page.body                                                             form.click_button()

 # disable keep_alive, when running into                      # forms, links, frames                                                # Submitting a form with a specific button
 # problems with session timeouts or getting an               page.forms, page.links, frames                                        form.click_button(form.button_with(:name => 'OK')
 # EOFError
                                                              # Selecting by criteria follows the pattern:                          # Form elements
 agent.keep_alive = false                                                                                                           form.fields, form.buttons, form.file_uploads, form.radio_buttons,
                                                              # page.element(s)_with(:criteria => value)
                                                              # The plural form (.elements) returns an                              form.checkboxes
 # Setting user agent:                                        # array, the singular form (.element) the
 agent.user_agent = 'Friendly Mechanize Script"               # first matching element or nil. Criteria                             # Form elements can be selected just like page elements
                                                              # is an attribute symbol and value may be                             # form.element(s)_with(:criteria => value)
 # Using one of the predefined user agents:                   # a string or a regular expression. If no                             # e.g.:
 # 'Mechanize', 'Mac Mozilla', 'Linux Mozilla'.               # criteria attributr is given, :name will                             form.field_with(:name => 'password')
                                                              # be used. e.g.:                                                      form.field_with('password')
 # 'Windows IE 6', 'iPhone', 'Linux Konqueror',
                                                              page.form_with(:name => 'formName')                                   form.checkboxes(:value => /view_.*/)
 # 'Windows IE 7', 'Mac FireFox', 'Mac Safari',
                                                              page.form_with('formName')
 # 'Windows Mozilla'                                                                                                                # Field values can also be selected directly by their name
                                                              page.links_with(:text => /[0-9]*/
 agent.user_agent_alias = 'Mac Safari'                                                                                              form.password = 'secret'

 # To verify server certificates:                                                                                                   # Setting field values
 # (A collection of certificates is available                                                                                       # field       : .value = 'something'
 # here: http://curl.haxx.se/ca/ )                                                                                                  # checkbox    : .(un)check / .checked = true|false
                                                                                                                                    # radio_button: .(un)check / .checked = true|false
 agent.ca_file = 'cacert.pem'
                                                                                                                                    # file_upload : .file_name = '/tmp/upload.dat'


                                                                            Ruby / Mechanize
                                                                                                                                    # e.g.:
 # Don't follow HTTP redirects                                                                                                      form.field_with('foo').value = 'something'
 agent.redirect_ok = false                                                                                                          form.checkbox_with(:value => 'blue').uncheck
                                                                                        http://mechanize.rubyforge.org/mechanize/   form.radio_buttons[3].check
 # Follow refresh in meta tags
 agent.follow_meta_refresh = true                                                               Nokogiri                            # Select lists / drop down fields:
                                                                                                                                    form.field_with('color').option[2].select
                                                                                                   http://nokogiri.org/             form.field_with('color').options.find{|o| o.value == 'red'}.select
 # Enable logging
                                                                                                                                    form.field_with('color').select_none
 require 'logger'                                                                                                                   form.field_with('color').select_all
 agent.log = Logger.new('mechanize.log')


                                                                                                                                                    Parsing the page content
                                                                                                                                    # Selecting elements from the documents DOM
                                                                                     Hello Mechanize!                               nodes = agent.page.search('expression')
                                                                                                                                    nodes = agent.page / 'expression'
                                                             require 'rubygems'
                                                             require 'mechanize'
           Navigation/History                                                                                                       # Selecting the first matching element or nil
                                                             agent = WWW::Mechanize.new                                             node = agent.page.at('expression')
# load a page                                                agent.get('http://rubyforge.org/')
agent.get('http://the.internet.net')                                                                                                # 'expression' might be an XPath or CSS selector
                                                             agent.page.forms.first.words = 'mechanize'                             nodes = agent.page.search('//h2/a[@class="title"]')
# Go back to the last page:                                  agent.page.forms.first.click_button                                    nodes = agent.page.search('.h2 a.title')
agent.back
                                                             agent.page.link_with(:text => /WWW::Mechanize/).click
                                                             agent.page.link_with(:text => 'Files').click
                                                                                                                                    # navigating the document tree:
# Follow a link by its text
agent.link_with(:text => 'click me').click                                                                                          node.parent
                                                             links = agent.page / 'strong/a'                                        node.children
# Backup history, execute block and                          version = links.find do |link|
# restore history                                              link['href'] =~ /shownotes.*release_id/                              # node content and attributes
agent.transact do                                            end.text                                                               node.text
  ...                                                                                                                               node.inner_html
end                                                          puts "Hello Mechanize #{version}!"
                                                                                                                                    node.attributes['width']

                                                                                                                                    # found nodes, can be searched the same way
                                                                                                                                    rows = agent.page / 'table/tr'
Version 2010-01-30                           Creative Commons License                                                               value = rows[0].at('td[@class="value"]').text
(c) 2010 Tobias Grimm                        http://creativecommons.org/licenses/by/3.0

More Related Content

What's hot

Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2Javier Eguiluz
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8kgoel1
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8kgoel1
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiPivorak MeetUp
 
Everything you always wanted to know about forms* *but were afraid to ask
Everything you always wanted to know about forms* *but were afraid to askEverything you always wanted to know about forms* *but were afraid to ask
Everything you always wanted to know about forms* *but were afraid to askAndrea Giuliano
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with ReactGreeceJS
 
Django Templates
Django TemplatesDjango Templates
Django TemplatesWilly Liu
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Sumy PHP User Grpoup
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsTse-Ching Ho
 
Send, pass, get variables with php, form, html & java script code
Send, pass, get variables with php, form, html & java script codeSend, pass, get variables with php, form, html & java script code
Send, pass, get variables with php, form, html & java script codeNoushadur Shoukhin
 
Ch9 .Best Practices for Class-Based Views
Ch9 .Best Practices  for  Class-Based ViewsCh9 .Best Practices  for  Class-Based Views
Ch9 .Best Practices for Class-Based ViewsWilly Liu
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...Atlassian
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails Hung Wu Lo
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Building Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModelBuilding Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModelpauldix
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 

What's hot (20)

Rails <form> Chronicle
Rails <form> ChronicleRails <form> Chronicle
Rails <form> Chronicle
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
 
Drupal8 simplepage v2
Drupal8 simplepage v2Drupal8 simplepage v2
Drupal8 simplepage v2
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
 
Everything you always wanted to know about forms* *but were afraid to ask
Everything you always wanted to know about forms* *but were afraid to askEverything you always wanted to know about forms* *but were afraid to ask
Everything you always wanted to know about forms* *but were afraid to ask
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with React
 
Django Templates
Django TemplatesDjango Templates
Django Templates
 
Django Bogotá. CBV
Django Bogotá. CBVDjango Bogotá. CBV
Django Bogotá. CBV
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in rails
 
Leveraging Symfony2 Forms
Leveraging Symfony2 FormsLeveraging Symfony2 Forms
Leveraging Symfony2 Forms
 
Send, pass, get variables with php, form, html & java script code
Send, pass, get variables with php, form, html & java script codeSend, pass, get variables with php, form, html & java script code
Send, pass, get variables with php, form, html & java script code
 
Ch9 .Best Practices for Class-Based Views
Ch9 .Best Practices  for  Class-Based ViewsCh9 .Best Practices  for  Class-Based Views
Ch9 .Best Practices for Class-Based Views
 
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Building Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModelBuilding Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModel
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 

Viewers also liked

Khóa học đánh dj chuyên nghiệp
Khóa học đánh dj chuyên nghiệpKhóa học đánh dj chuyên nghiệp
Khóa học đánh dj chuyên nghiệpGóc chia sẻ
 
Diet clinic noida health care
Diet clinic noida health careDiet clinic noida health care
Diet clinic noida health carepkdietclinic
 
Entrenamiento del dia jueves 21 06-2012
Entrenamiento del dia jueves 21 06-2012Entrenamiento del dia jueves 21 06-2012
Entrenamiento del dia jueves 21 06-2012Diego Rojas
 
saabab_cbrne_transportpackaging_2015_web
saabab_cbrne_transportpackaging_2015_websaabab_cbrne_transportpackaging_2015_web
saabab_cbrne_transportpackaging_2015_webPeter Richards
 

Viewers also liked (9)

Khóa học đánh dj chuyên nghiệp
Khóa học đánh dj chuyên nghiệpKhóa học đánh dj chuyên nghiệp
Khóa học đánh dj chuyên nghiệp
 
Curso tablet e lousa
Curso tablet e lousaCurso tablet e lousa
Curso tablet e lousa
 
Vinay Sharma Resume
Vinay Sharma ResumeVinay Sharma Resume
Vinay Sharma Resume
 
Official Resume
Official ResumeOfficial Resume
Official Resume
 
Ravindra_Resume
Ravindra_ResumeRavindra_Resume
Ravindra_Resume
 
Diet clinic noida health care
Diet clinic noida health careDiet clinic noida health care
Diet clinic noida health care
 
Entrenamiento del dia jueves 21 06-2012
Entrenamiento del dia jueves 21 06-2012Entrenamiento del dia jueves 21 06-2012
Entrenamiento del dia jueves 21 06-2012
 
saabab_cbrne_transportpackaging_2015_web
saabab_cbrne_transportpackaging_2015_websaabab_cbrne_transportpackaging_2015_web
saabab_cbrne_transportpackaging_2015_web
 
Mulut
MulutMulut
Mulut
 

Similar to SAVIA

Functional testing with capybara
Functional testing with capybaraFunctional testing with capybara
Functional testing with capybarakoffeinfrei
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful RailsViget Labs
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful RailsBen Scofield
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011Arun Gupta
 
Ember.js for Big Profit
Ember.js for Big ProfitEmber.js for Big Profit
Ember.js for Big ProfitCodeCore
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.jsjubilem
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfoliovitabile
 
R Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioR Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioRobert Tanenbaum
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - IntroductionABC-GROEP.BE
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesSiarhei Barysiuk
 

Similar to SAVIA (20)

Functional testing with capybara
Functional testing with capybaraFunctional testing with capybara
Functional testing with capybara
 
Capybara
CapybaraCapybara
Capybara
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
Ember.js for Big Profit
Ember.js for Big ProfitEmber.js for Big Profit
Ember.js for Big Profit
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
Cmsc 100 (web forms)
Cmsc 100 (web forms)Cmsc 100 (web forms)
Cmsc 100 (web forms)
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.js
 
Iktomi lightning talk
Iktomi lightning talkIktomi lightning talk
Iktomi lightning talk
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
68837.ppt
68837.ppt68837.ppt
68837.ppt
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
 
R Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioR Tanenbaum .Net Portfolio
R Tanenbaum .Net Portfolio
 
Web I - 04 - Forms
Web I - 04 - FormsWeb I - 04 - Forms
Web I - 04 - Forms
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
Rhino Mocks
Rhino MocksRhino Mocks
Rhino Mocks
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

SAVIA

  • 1. The Agent Accessing page elements Forms # The current page # Submitting a form without a button: require 'rubygems' form.submit agent.page require 'mechanize' # The HTML page content # Submitting a form with the default button agent = WWW::Mechanize.new page.body form.click_button() # disable keep_alive, when running into # forms, links, frames # Submitting a form with a specific button # problems with session timeouts or getting an page.forms, page.links, frames form.click_button(form.button_with(:name => 'OK') # EOFError # Selecting by criteria follows the pattern: # Form elements agent.keep_alive = false form.fields, form.buttons, form.file_uploads, form.radio_buttons, # page.element(s)_with(:criteria => value) # The plural form (.elements) returns an form.checkboxes # Setting user agent: # array, the singular form (.element) the agent.user_agent = 'Friendly Mechanize Script" # first matching element or nil. Criteria # Form elements can be selected just like page elements # is an attribute symbol and value may be # form.element(s)_with(:criteria => value) # Using one of the predefined user agents: # a string or a regular expression. If no # e.g.: # 'Mechanize', 'Mac Mozilla', 'Linux Mozilla'. # criteria attributr is given, :name will form.field_with(:name => 'password') # be used. e.g.: form.field_with('password') # 'Windows IE 6', 'iPhone', 'Linux Konqueror', page.form_with(:name => 'formName') form.checkboxes(:value => /view_.*/) # 'Windows IE 7', 'Mac FireFox', 'Mac Safari', page.form_with('formName') # 'Windows Mozilla' # Field values can also be selected directly by their name page.links_with(:text => /[0-9]*/ agent.user_agent_alias = 'Mac Safari' form.password = 'secret' # To verify server certificates: # Setting field values # (A collection of certificates is available # field : .value = 'something' # here: http://curl.haxx.se/ca/ ) # checkbox : .(un)check / .checked = true|false # radio_button: .(un)check / .checked = true|false agent.ca_file = 'cacert.pem' # file_upload : .file_name = '/tmp/upload.dat' Ruby / Mechanize # e.g.: # Don't follow HTTP redirects form.field_with('foo').value = 'something' agent.redirect_ok = false form.checkbox_with(:value => 'blue').uncheck http://mechanize.rubyforge.org/mechanize/ form.radio_buttons[3].check # Follow refresh in meta tags agent.follow_meta_refresh = true Nokogiri # Select lists / drop down fields: form.field_with('color').option[2].select http://nokogiri.org/ form.field_with('color').options.find{|o| o.value == 'red'}.select # Enable logging form.field_with('color').select_none require 'logger' form.field_with('color').select_all agent.log = Logger.new('mechanize.log') Parsing the page content # Selecting elements from the documents DOM Hello Mechanize! nodes = agent.page.search('expression') nodes = agent.page / 'expression' require 'rubygems' require 'mechanize' Navigation/History # Selecting the first matching element or nil agent = WWW::Mechanize.new node = agent.page.at('expression') # load a page agent.get('http://rubyforge.org/') agent.get('http://the.internet.net') # 'expression' might be an XPath or CSS selector agent.page.forms.first.words = 'mechanize' nodes = agent.page.search('//h2/a[@class="title"]') # Go back to the last page: agent.page.forms.first.click_button nodes = agent.page.search('.h2 a.title') agent.back agent.page.link_with(:text => /WWW::Mechanize/).click agent.page.link_with(:text => 'Files').click # navigating the document tree: # Follow a link by its text agent.link_with(:text => 'click me').click node.parent links = agent.page / 'strong/a' node.children # Backup history, execute block and version = links.find do |link| # restore history link['href'] =~ /shownotes.*release_id/ # node content and attributes agent.transact do end.text node.text ... node.inner_html end puts "Hello Mechanize #{version}!" node.attributes['width'] # found nodes, can be searched the same way rows = agent.page / 'table/tr' Version 2010-01-30 Creative Commons License value = rows[0].at('td[@class="value"]').text (c) 2010 Tobias Grimm http://creativecommons.org/licenses/by/3.0