SlideShare a Scribd company logo
   
    WWW::Mechanize
    Márcio Vitor De Matos Silva ­ cromo.jml@gmail.com




                            
WWW::Mechanize

      Criador e Project Owner 
      Andy Lester 'PetDance'

             Licença 
        Artistic License/GPL

         Versão estável 
         1.34 – 09/12/2007

     Versão desenvolvimento 
       1.49_01 – 27/09/2008 
                   
Usos úteis e comuns 
     Preenchimento de formulários

     Percorrer e clicar links

     Testes automatizados

     Enviar referers, user­agents, uso de  proxys

     Acessar histórico de urls visitados
                      
De onde vem a força ?
         LWP::UserAgent
         HTTP::Request
         HTTP::Cookies
         HTML::TokeParser
         URI
         ...

                
LWP::UserAgent
            WWW::Mechanize


     Conceitos e propósitos diferentes.


  Mechanize abstrai dificuldades do 
LWP::UserAgent


                         
Ambiente
    Instalação
     cpan> install WWW::Mechanize
    Documentação
     perldoc WWW::Mechanize
    Uso
     use WWW::Mechanize;
    Construtor
     my $mech = WWW::Mechanize­>new();
                     
Capturando uma página

    use WWW::Mechanize;
    my $mech = WWW::Mechanize­>new();
    $mech­>get(“http://www.retbeer.com/”);
    print $mech­>title.$/;



                      
$mech­>agent

  Get/set que define o user­agent usado durante 
a navegação

  Também pode ser definida no método 
construtor:
    my $mech = WWW::Mechanize­>new( agent => 
     ’wonderbot 1.01’ );

                          
Enviando um agent
    my $mech = new WWW::Mechanize;
    $mech­>get('http://www.perl.org.br');
    $mech­>agent(“TestBot/1.0”);
    if($mech­>success) {
       print $mech­>content;
    }
    else {
       print $mech­>response­>error_as_HTML;
    }
                      
$mech­>add_header
   Permite adicionar parâmetros ao header da 
requisição

$mech­>add_header( Referer => 
'http://www.retbeer.com' );

$mech­>add_header( Referer => undef );

$mech­>add_header( Encoding => ’text/klingon’ );
                         
$mech­>find_all_links
 
   Retorna todos os links seguindo algum 
critério:
    $mech­>get( $url );
    my @links = $mech­>find_all_links( text_regex 
 => qr/Cinema/i );
    foreach my $link (@links)  {
                $mech­>get( $link­>url_abs );
                return $mech­>content;
     }                          
$mech­>follow_link
       'Clica' o link seguinte o critério escolhido

    $mech­>get('http://www.retbeer.com');
    foreach my $categoria qw(vinho cerveja vodka) {
       $mech­>follow_link( text_regex => qr/$categoria/i );
       if ($mech­>success) {
           print $categoria.$/;
           print $mech­>content;
           $mech­>back;
 
       }                         

    }
$mech­>submit_form

     Formulários por form_number/form_name

     Preenchimento de campos

     Submit de forms



                              
                           
Submetendo um formulário
          use WWW::Mechanize; 
          my $mech = WWW::Mechanize­>new(); 
          $mech­>get( 'http://www.retbeer.com' ); 

          $mech­>submit_form( 
                    form_name => 'form_login', 
                    fields      => { 
                        username    => 'mungo', 
                        password    => 'lost­and­alone', 
                    } 
               );                   
Test::WWW::Mechanize

    Sub classe WWW::Mechanize
   Incorpora features para testes de aplicações 
web:
       Base
       Conteúdo html
       Links
       Formulários

                          
Realizando testes
    use Test::WWW::Mechanize;
    use Test::More tests => 4;

    my $mech = Test::WWW::Mechanize­>new;
    $mech­>get_ok( 'http://www.perl.org.br/ ');
    $mech­>base_is( 'http://www.perl.org.br/Main/WebHome' ,quot;Basequot;);
    $mech­>title_is( quot;Perl Brasil ­ WebHomequot;,quot;Titlequot;);
    $mech­>content_contains( quot;Artigos quot;,quot;Artigosquot; );


    # perl  teste_perlbr.pl
    1..4
    ok 1 ­ GET http://www.perl.org.br/ 
    ok 2 ­ Base
    ok 3 ­ Title
    ok 4 ­ Artigos                         
Exemplo de uso real
        my $login    = quot;login_namequot;;
        my $password = quot;passwordquot;;
        my $folder   = quot;folderquot;;
        my $url = quot;http://img78.photobucket.com/albums/v281/$login/$folder/quot;;
        # login to your photobucket.com account
        my $mech = WWW::Mechanize­>new();
        $mech­>get($url);
        $mech­>submit_form(
            form_number => 1,
            fields      => { password => $password },
        );
        die unless ($mech­>success);
        # upload image files specified on command line
        foreach (@ARGV) {
            print quot;$_nquot;;
            $mech­>form_number(2);
            $mech­>field('the_file[]' => $_);
            $mech­>submit();
        }                                  
Referências

                       CPAN
          http://search.cpan.org/dist/WWW­
          Mechanize/lib/WWW/Mechanize.pm 
                      Mailing list 
    http://groups.google.com/group/www­mechanize­
                           users
                     Google Code 
       http://code.google.com/p/www­mechanize/
                          
Fontes de pesquisa:
     man WWW::Mechanize
     Spidering Hacks
      HEMENWAY, Kevin e CALISHAIN, Tara. 
      Cambridge, Massachusetts: O'Reilly, 2003.
      ISBN 0­596­00577­6.
     Automated web site testing with WWW::Mechanize 
     with Andy Lester
      http://www.webgui.org/wgtv/wwwmechanize

                           
THE END



        

More Related Content

What's hot

Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale teslaecoe...
Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale  teslaecoe...Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale  teslaecoe...
Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale teslaecoe...Miroslav Miskovic
 
So you want to build a Facebook app
So you want to build a Facebook appSo you want to build a Facebook app
So you want to build a Facebook app
kamal.fariz
 
Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.
Jason Morrison
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
rahoulb
 
High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)
Stoyan Stefanov
 
Fast by Default
Fast by DefaultFast by Default
Fast by Default
Abhay Kumar
 
Object Exercise
Object ExerciseObject Exercise
Object Exercise
Workhorse Computing
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
Takatsugu Shigeta
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
Takatsugu Shigeta
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
DanWooster1
 
My PPP Project / Digital Resume
My PPP Project / Digital ResumeMy PPP Project / Digital Resume
My PPP Project / Digital Resume
ARRuggiero
 
Turbogears Presentation
Turbogears PresentationTurbogears Presentation
Turbogears Presentation
didip
 
Progressive What Apps?
Progressive What Apps?Progressive What Apps?
Progressive What Apps?
Patrick Kettner
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
Vivian S. Zhang
 
DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)
dpc
 
Secure WordPress Development Practices
Secure WordPress Development PracticesSecure WordPress Development Practices
Secure WordPress Development Practices
Brandon Dove
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesBrandon Dove
 
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LABHTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
priya Nithya
 
High-Quality JavaScript
High-Quality JavaScriptHigh-Quality JavaScript
High-Quality JavaScript
Marc Bächinger
 

What's hot (20)

Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale teslaecoe...
Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale  teslaecoe...Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale  teslaecoe...
Energy ~ nikola tesla secret ~ 9 79% conv ~ 100% comm of $110 sale teslaecoe...
 
So you want to build a Facebook app
So you want to build a Facebook appSo you want to build a Facebook app
So you want to build a Facebook app
 
Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
 
High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)
 
Fast by Default
Fast by DefaultFast by Default
Fast by Default
 
Object Exercise
Object ExerciseObject Exercise
Object Exercise
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
 
My PPP Project / Digital Resume
My PPP Project / Digital ResumeMy PPP Project / Digital Resume
My PPP Project / Digital Resume
 
Turbogears Presentation
Turbogears PresentationTurbogears Presentation
Turbogears Presentation
 
Progressive What Apps?
Progressive What Apps?Progressive What Apps?
Progressive What Apps?
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)
 
Secure WordPress Development Practices
Secure WordPress Development PracticesSecure WordPress Development Practices
Secure WordPress Development Practices
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LABHTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
 
High-Quality JavaScript
High-Quality JavaScriptHigh-Quality JavaScript
High-Quality JavaScript
 

Viewers also liked

Twittness - O Twitter em forma de solução para os negócios
Twittness - O Twitter em forma de solução para os negóciosTwittness - O Twitter em forma de solução para os negócios
Twittness - O Twitter em forma de solução para os negócios
mvitor
 
Twittness
TwittnessTwittness
Twittness
mvitor
 
ITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativoITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativo
mvitor
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
Rachel Andrew
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
Ethos3
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
Shelly Sanchez Terrell
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
Chris Lema
 

Viewers also liked (7)

Twittness - O Twitter em forma de solução para os negócios
Twittness - O Twitter em forma de solução para os negóciosTwittness - O Twitter em forma de solução para os negócios
Twittness - O Twitter em forma de solução para os negócios
 
Twittness
TwittnessTwittness
Twittness
 
ITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativoITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativo
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 

Similar to WWW:::Mechanize YAPC::BR 2008

More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
jeresig
 
Professional JavaScript Development - Creating Reusable Code
Professional JavaScript Development -  Creating Reusable CodeProfessional JavaScript Development -  Creating Reusable Code
Professional JavaScript Development - Creating Reusable CodeWildan Maulana
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
bturnbull
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On RailsWen-Tien Chang
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
Javier Eguiluz
 
Neil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do ItNeil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do It
Carsonified Team
 
Scaling Rails Presentation
Scaling Rails PresentationScaling Rails Presentation
Scaling Rails Presentationeraz
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remoteask bills
 
Blueprint talk at Open Hackday London 2009
Blueprint talk at Open Hackday London 2009Blueprint talk at Open Hackday London 2009
Blueprint talk at Open Hackday London 2009
Ricardo Varela
 
REST, the internet as a database?
REST, the internet as a database?REST, the internet as a database?
REST, the internet as a database?
Andrej Koelewijn
 
Developing PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan FrameworkDeveloping PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan Framework
Raymond Irving
 
Spyware/Malware FVCP
Spyware/Malware  FVCPSpyware/Malware  FVCP
Spyware/Malware FVCP
Pete DuMelle
 
August 10th, 2009 Pete De Mulle Twitter
August 10th, 2009 Pete De Mulle TwitterAugust 10th, 2009 Pete De Mulle Twitter
August 10th, 2009 Pete De Mulle Twitter
Straight North
 
FVCP - Facebook , Twitter and Meetup API / Widgets
FVCP - Facebook , Twitter and Meetup API / WidgetsFVCP - Facebook , Twitter and Meetup API / Widgets
FVCP - Facebook , Twitter and Meetup API / Widgets
Pete DuMelle
 
Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力
Yoji Shidara
 
Merb Pluming - The Router
Merb Pluming - The RouterMerb Pluming - The Router
Merb Pluming - The Routercarllerche
 
Sinatra
SinatraSinatra
So you want to build a facebook App ?
So you want to build a facebook App ?So you want to build a facebook App ?
So you want to build a facebook App ?Nguyễn Duy Nhân
 

Similar to WWW:::Mechanize YAPC::BR 2008 (20)

More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
Satchmo
SatchmoSatchmo
Satchmo
 
Professional JavaScript Development - Creating Reusable Code
Professional JavaScript Development -  Creating Reusable CodeProfessional JavaScript Development -  Creating Reusable Code
Professional JavaScript Development - Creating Reusable Code
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Neil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do ItNeil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do It
 
Scaling Rails Presentation
Scaling Rails PresentationScaling Rails Presentation
Scaling Rails Presentation
 
Perlbal Tutorial
Perlbal TutorialPerlbal Tutorial
Perlbal Tutorial
 
Esposito Ajax Remote
Esposito Ajax RemoteEsposito Ajax Remote
Esposito Ajax Remote
 
Blueprint talk at Open Hackday London 2009
Blueprint talk at Open Hackday London 2009Blueprint talk at Open Hackday London 2009
Blueprint talk at Open Hackday London 2009
 
REST, the internet as a database?
REST, the internet as a database?REST, the internet as a database?
REST, the internet as a database?
 
Developing PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan FrameworkDeveloping PHP Web Applications with the Raxan Framework
Developing PHP Web Applications with the Raxan Framework
 
Spyware/Malware FVCP
Spyware/Malware  FVCPSpyware/Malware  FVCP
Spyware/Malware FVCP
 
August 10th, 2009 Pete De Mulle Twitter
August 10th, 2009 Pete De Mulle TwitterAugust 10th, 2009 Pete De Mulle Twitter
August 10th, 2009 Pete De Mulle Twitter
 
FVCP - Facebook , Twitter and Meetup API / Widgets
FVCP - Facebook , Twitter and Meetup API / WidgetsFVCP - Facebook , Twitter and Meetup API / Widgets
FVCP - Facebook , Twitter and Meetup API / Widgets
 
Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力
 
Merb Pluming - The Router
Merb Pluming - The RouterMerb Pluming - The Router
Merb Pluming - The Router
 
Sinatra
SinatraSinatra
Sinatra
 
So you want to build a facebook App ?
So you want to build a facebook App ?So you want to build a facebook App ?
So you want to build a facebook App ?
 

Recently uploaded

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

WWW:::Mechanize YAPC::BR 2008

  • 1.     WWW::Mechanize Márcio Vitor De Matos Silva ­ cromo.jml@gmail.com    
  • 2. WWW::Mechanize  Criador e Project Owner  Andy Lester 'PetDance' Licença  Artistic License/GPL Versão estável  1.34 – 09/12/2007 Versão desenvolvimento    1.49_01 – 27/09/2008   
  • 3. Usos úteis e comuns   Preenchimento de formulários  Percorrer e clicar links  Testes automatizados  Enviar referers, user­agents, uso de  proxys  Acessar histórico de urls visitados    
  • 4. De onde vem a força ?  LWP::UserAgent  HTTP::Request  HTTP::Cookies  HTML::TokeParser  URI  ...    
  • 5. LWP::UserAgent WWW::Mechanize  Conceitos e propósitos diferentes.  Mechanize abstrai dificuldades do  LWP::UserAgent    
  • 6. Ambiente Instalação cpan> install WWW::Mechanize Documentação perldoc WWW::Mechanize Uso use WWW::Mechanize; Construtor my $mech = WWW::Mechanize­>new();    
  • 7. Capturando uma página use WWW::Mechanize; my $mech = WWW::Mechanize­>new(); $mech­>get(“http://www.retbeer.com/”); print $mech­>title.$/;    
  • 8. $mech­>agent Get/set que define o user­agent usado durante  a navegação Também pode ser definida no método  construtor: my $mech = WWW::Mechanize­>new( agent =>  ’wonderbot 1.01’ );    
  • 9. Enviando um agent my $mech = new WWW::Mechanize; $mech­>get('http://www.perl.org.br'); $mech­>agent(“TestBot/1.0”); if($mech­>success) { print $mech­>content; } else { print $mech­>response­>error_as_HTML; }    
  • 11. $mech­>find_all_links   Retorna todos os links seguindo algum  critério:    $mech­>get( $url );    my @links = $mech­>find_all_links( text_regex  => qr/Cinema/i );    foreach my $link (@links)  {                $mech­>get( $link­>url_abs );                return $mech­>content;   }  
  • 12. $mech­>follow_link  'Clica' o link seguinte o critério escolhido $mech­>get('http://www.retbeer.com'); foreach my $categoria qw(vinho cerveja vodka) { $mech­>follow_link( text_regex => qr/$categoria/i ); if ($mech­>success) { print $categoria.$/; print $mech­>content;     $mech­>back;   }   }
  • 13. $mech­>submit_form  Formulários por form_number/form_name  Preenchimento de campos  Submit de forms            
  • 14. Submetendo um formulário      use WWW::Mechanize;       my $mech = WWW::Mechanize­>new();       $mech­>get( 'http://www.retbeer.com' );       $mech­>submit_form(                 form_name => 'form_login',                 fields      => {                     username    => 'mungo',                     password    => 'lost­and­alone',                 }              );   
  • 15. Test::WWW::Mechanize   Sub classe WWW::Mechanize  Incorpora features para testes de aplicações  web:  Base  Conteúdo html  Links  Formulários    
  • 16. Realizando testes use Test::WWW::Mechanize; use Test::More tests => 4; my $mech = Test::WWW::Mechanize­>new; $mech­>get_ok( 'http://www.perl.org.br/ '); $mech­>base_is( 'http://www.perl.org.br/Main/WebHome' ,quot;Basequot;); $mech­>title_is( quot;Perl Brasil ­ WebHomequot;,quot;Titlequot;); $mech­>content_contains( quot;Artigos quot;,quot;Artigosquot; ); # perl  teste_perlbr.pl 1..4 ok 1 ­ GET http://www.perl.org.br/  ok 2 ­ Base ok 3 ­ Title   ok 4 ­ Artigos  
  • 17. Exemplo de uso real     my $login    = quot;login_namequot;;     my $password = quot;passwordquot;;     my $folder   = quot;folderquot;;     my $url = quot;http://img78.photobucket.com/albums/v281/$login/$folder/quot;;     # login to your photobucket.com account     my $mech = WWW::Mechanize­>new();     $mech­>get($url);     $mech­>submit_form(         form_number => 1,         fields      => { password => $password },     );     die unless ($mech­>success);     # upload image files specified on command line     foreach (@ARGV) {         print quot;$_nquot;;         $mech­>form_number(2);         $mech­>field('the_file[]' => $_);         $mech­>submit();       }  
  • 18. Referências CPAN http://search.cpan.org/dist/WWW­ Mechanize/lib/WWW/Mechanize.pm  Mailing list  http://groups.google.com/group/www­mechanize­ users Google Code  http://code.google.com/p/www­mechanize/    
  • 19. Fontes de pesquisa:  man WWW::Mechanize  Spidering Hacks HEMENWAY, Kevin e CALISHAIN, Tara.  Cambridge, Massachusetts: O'Reilly, 2003. ISBN 0­596­00577­6.  Automated web site testing with WWW::Mechanize   with Andy Lester http://www.webgui.org/wgtv/wwwmechanize