Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, how can I extract the email button the js button on this page:

https://reporter.nih.gov/project-details/10573139

Here's some code I've written that gives me a pdf but I need to have the script click the button before I grab the pdf and I can't figure that out. I tried to see if I could 'tab' to it as I could automate that with 13 tabs and a return or something but the button doesn't select. Any ideas/help are greatly appreciated.

use strict; use File::Spec; use File::Basename 'dirname'; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; my $url = 'https://reporter.nih.gov/project-details/11011199'; my $mech = WWW::Mechanize::Chrome->new( headless => 1, # otherwise, PDF printing will not work ); print "Loading $url"; $mech->get($url); sleep 5; my $fn= 'screen.pdf'; my $page_pdf = $mech->content_as_pdf( filename => $fn, ); print "\nSaved $url as $fn\n";

Replies are listed 'Best First'.
Re: How can I extract an email behind a JS button?
by Corion (Patriarch) on Mar 15, 2024 at 06:47 UTC

    I don't see any code that tries to identify the button to click, nor any code that tries to click it.

    Can you be more specific where you need help? This is not a code writing service.

      Hi Corion, here is what I tried as far as mimicking what the button click did. I used Mozilla developer to look at the post command and used the transmitted data however what I'm sending looking to be in the wrong format as it's returning an error. From what I know it's supped to be in this format and what I used is right after:

      $mech->post(Request_URL, Content => {FORM_FIELDS...});

      $mech->post(https://reporter.nih.gov/services/Projects/PiPoEmails, Content => {project_id:”10702248”});
      $mech->post(https://reporter.nih.gov/services/Projects/PiPoEmails, Con +tent => {recaptcha:"03AFcWeA7e6fsRQ02z43ij7N6u2b9lXbajsQs_cLex50-fcjO +zm8w17PogPUhTf2cTarSroDhsqdGVng0ZMJNtI_yykUez7G8bIDhaL6y2AD1W4JJrzTkG +jDiqa_S-yHy15f2jVN-oSPB_idz9PvvYUGZ60ZeJq7WHA7VJJFbp-qha3RGA2A3RmA9ri +vViSdSK_pCYMVGzuGrQCX3ym-0TXy6a2xWVOSijy6fG0ReXO-8IhYtnSn_uUstoAZSfCK +xRJzquCh2EmIb41GTOrApRN-osiE-1l4cc84tKvngBoiUsLiOeTJasoudWCQ-9ID3eUtj +ucB6wKEVwtdvBCxdLlidPL5E9wHQUiJFGl-sun6gEzqVfZ4nQfUTi-CZ0SB2GJhu2-EDI +pkBdq75AzwwjHqT5vS-Q_PS11hRAosELBWf3-RY_DyrG5iYJhuFFerZOE4ymD20EN9hKw +_tAkPuFi9OkKXFNsiGx0toZ5jIFiPJaSe1EaAShNfW8Vy_f7BMDEo3U6Kx-dKEyDL3zHm +smyCeXZDsiyeDWfvQEoET1tESwZjQVhHDuDZUHwhYZKZUPMFVI3MvhxHglIkrxOcllwv7 +NUopJxnS9TOrU6uQG1ag56DMZ36EZ3RFRBrvEXn430ek8I89SqcyYWDwkjMvg3dkjBct4 +3QstZw"});

      If someone could LMK where the formatting errors are in what I'm posting I'd greatly appreciate it. Thanks!

        You need to learn and understand what you are seeing.

        The POST is the solved Recaptcha to verify that you are human. You cannot easily replicate that using a POST command.

        I would guess that the best approach is to use the ->click() command.

Re: How can I extract an email behind a JS button?
by cavac (Prior) on Mar 15, 2024 at 19:23 UTC

    If it's one of these "I am not a bot"-like bot detection thingies, you might need some mouse interaction. Luckily, Perl got you covered.

    Last year, i wrote a post on how to write an Autoclicker: Autoclicker! Cheating is winning, too!

    Maybe all you need is to automate your browser, then grab the file from your Browsers download folder.

    Or if you are after some data within the page, you could just make the script move the mouse pointer to the beginning of it, hold down left mouse button and move the pointer to the end (depending on the data, a double-click might also mark it). Then press CTRL and C, and voila, the requested data is in your clipboard. Perl got cou covered there, too: Clipboard

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP

      Thanks for sharing Cavac, I'll check it out and LYK if I have questions.