SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
   
    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



        

Mais conteúdo relacionado

Mais procurados

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 appkamal.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 Storiesrahoulb
 
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
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With BloggingTakatsugu Shigeta
 
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4DanWooster1
 
My PPP Project / Digital Resume
My PPP Project / Digital ResumeMy PPP Project / Digital Resume
My PPP Project / Digital ResumeARRuggiero
 
Turbogears Presentation
Turbogears PresentationTurbogears Presentation
Turbogears Presentationdidip
 
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 PracticesBrandon 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# LABpriya Nithya
 

Mais procurados (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
 

Destaque

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óciosmvitor
 
Twittness
TwittnessTwittness
Twittnessmvitor
 
ITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativoITIL versus COBIT - Um breve comparativo
ITIL versus COBIT - Um breve comparativomvitor
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSSRachel Andrew
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back KidEthos3
 
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 AdolescentsShelly 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 LemaChris Lema
 

Destaque (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
 

Semelhante a WWW:::Mechanize YAPC::BR 2008

More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
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 2009bturnbull
 
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 4Javier 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 ItCarsonified 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 2009Ricardo 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 FrameworkRaymond Irving
 
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 TwitterStraight 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 / WidgetsPete DuMelle
 
Spyware/Malware FVCP
Spyware/Malware  FVCPSpyware/Malware  FVCP
Spyware/Malware FVCPPete 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
 
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
 

Semelhante a 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
 
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
 
Spyware/Malware FVCP
Spyware/Malware  FVCPSpyware/Malware  FVCP
Spyware/Malware FVCP
 
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 ?
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

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