Professional Web Applications Themes

Problems with WWW::Mechanize and Amazon - PERL Miscellaneous

I am currently trying to get WWW::Mechanize to work and am struggling with what I expected to be a simple example. I have managed to get Mechanize working with Google but not with Amazon. The following code runs but always opens a browser that displays an Amazon pages stating that there has been a bug in my browser. This occurs no matter what I set the Agent type to. I want to use WWW::Mechanize to create a mobile version of a web application I have and thought that Mechanize would be suitable but I'm now not so sure if I ...

  1. #1

    Default Problems with WWW::Mechanize and Amazon

    I am currently trying to get WWW::Mechanize to work and am struggling
    with what I expected to be a simple example. I have managed to get
    Mechanize working with Google but not with Amazon.

    The following code runs but always opens a browser that displays an
    Amazon pages stating that there has been a bug in my browser. This
    occurs no matter what I set the Agent type to.

    I want to use WWW::Mechanize to create a mobile version of a web
    application I have and thought that Mechanize would be suitable but
    I'm now not so sure if I cannot get it to work with something simple.

    I would really apprecaite any pointers that anyone might have on what
    the problem might be with the code or alternatives to Mechanize.

    Thanks

    Neil Thompson


    #!/usr/bin/perl

    # create a new browser
    use WWW::Mechanize;
    my $browser = WWW::Mechanize->new();


    # tell it to get the main page
    $browser->get("http://www.amazon.co.uk/");
    die "failed to get [url]www.amazon.co.uk[/url] ",
    $browser->response->status_line
    unless $browser->success;

    # okay, fill in the box with the name of the
    # module we want to look up
    $browser->form_number(1);
    $browser->field("field-keywords", "williams");
    $browser->field("url", "index=books-uk");
    $browser->click("Go");
    die "failed to get click go ", $browser->response->status_line
    unless $browser->success;

    my $url = $browser->uri;

    # launch a browser...

    system('explorer.exe', $url);

    # All done
    exit;
    Neil Thompson Guest

  2. #2

    Default Re: Problems with WWW::Mechanize and Amazon

    Neil Thompson wrote:
    > I am currently trying to get WWW::Mechanize to work and am struggling
    > with what I expected to be a simple example. I have managed to get
    > Mechanize working with Google but not with Amazon.
    you might want to use WWW::Mechanize::Shell
    > $browser->form_number(1);
    > $browser->field("field-keywords", "williams");
    > $browser->field("url", "index=books-uk");
    > $browser->click("Go");
    > die "failed to get click go ", $browser->response->status_line
    > unless $browser->success;
    > my $url = $browser->uri;
    ok, this is the url that was used for a POST-request.
    > # launch a browser...
    > system('explorer.exe', $url);
    how do you think this url would be enough for the browser?
    fill out the form yourself and then copy and paste the url
    and try to go to it: it will show you the same.
    you have to get the content of the request into a html-file
    and then let explorer show you that file.

    hth, tina
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - my mail address expires end of august 2003 -
    Tina Mueller Guest

Similar Threads

  1. mechanize question
    By Charlie in forum PERL Modules
    Replies: 1
    Last Post: November 9th, 05:57 AM
  2. Mechanize
    By Paul Kraus in forum PERL Beginners
    Replies: 10
    Last Post: November 14th, 03:18 PM
  3. WWW:MECHANIZE anyone?
    By Ryan in forum PERL Modules
    Replies: 2
    Last Post: October 4th, 04:45 AM
  4. :Mechanize and Cookies
    By Rob Hanson in forum PERL Beginners
    Replies: 0
    Last Post: September 2nd, 09:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139