With some prodding from shmem, I was able to make progress, culminating in the code post above for "Update 2".

However, I still can't match the text I want, becuase the page fetched with WWW::Mech differs from the text I get when I open the url in firefox and do view source.

This is either no longer a javascript issue, or if it is a javascript issue I don't understand how to troubleshoot it.

At any rate, to simply reiterate the test case for my problem (basically the same as Update 2 above, but shorter and simpler):

use strict; use warnings; use WWW::Mechanize; use Data::Dumper; my $price = '249,9'; print "price: $price\n"; my $url = 'http://www.baur.de/is-bin/INTERSHOP.enfinity/WFS/Baur-BaurD +e-Site/de_DE/-/EUR/BV_ExternalCall-Start?ArticleNo=515358&NUMSArt=444 +3504&NUMSArtPc=4488615&AffiliateID=pangora-bd&Name=pangora-produktdat +en-baur&ActionID=preis-produkt-suche-baur&WKZ=79&IWL=101'; my $mech = WWW::Mechanize->new(); $mech->agent('Firefox/1.0 (Windows; U; Win98; en-US; Localization; rv: +1.4) Gecko/20030624 Netscape/7.1 (ax)'); $mech->get( $url ); my $html = $mech->content; print "html from $url doesn't match $price\n" unless $html =~ /$price/ + ; print "but paste into browser and view source, and it does\n"; print "final url after firefox redirect (but not www::mech redirect) i +s something like " . 'http://www.baur.de/is-bin/INTERSHOP.enfinity/WF +S/Baur-BaurDe-Site/de_DE/-/EUR/BV_DisplayProductInformation-ArticleNo +;sid=7oVhaTsE5oZsaX6rnON4q25Uv6S6Ixu_PzIwW50ajEGxS04TwoV1a_bGFYiItw== +?ArticleNo=515358&ls=0&firstPage=true&showGewinnspiel=true&showW3B=fa +lse' . "\n"; # uncomment this to print html, which is totally different from what y +ou get from firefox, show source. # print "html: $html";
Can anyone prod me further in the right direction?

PS: I'm still wondering if I would get better results with Win32::IE::Mechanize or WWW::Selenium or Mozilla::Mechanize.

UPDATE: better user agent string after perrin comment.


In reply to WWW::Mechanize fetch differs from firefox browser result (was Re: WWW::Mechanize or WWW::Selenium with javascript redirect) by tphyahoo
in thread WWW::Mechanize or WWW::Selenium with javascript redirect by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.