Search code examples
javascripthtmlperlweb-scrapingwww-mechanize

Perl Click Button with WWW::Mechanize


I'm new to web scraping with Perl, and I'm trying to submit the page by filling in username and password fields, and clicking submit. I inspected the HTML code of the button in question, and it looks like:

<input type="submit" class="button formSubmission" value="Sign In">

I read that WWW::Mechanize can't handle JavaScript, but I'm not sure if the code I'm looking at is JavaScript, or my implementation is just wrong. I tried $mech->click_button("Sign In"); halfheartedly, but received the error that no such field existed.

Any ideas?


Solution

  • Your button doesn't have name attribute that's why I'm sure there is no need to click it. What you need is just submit your fields to the form:

    $mech->submit_form(
        with_fields => {
            your_username_field => $user,
            your_password_field => $password,
            .....
        },
    );