1

I am using WWW::Scripter to call a javascript. The link to the site is this. The html of the document looks like this.

<form id="whitelistForm" method="get" action="">
<table id="whitelistTable" class="info">
<tbody>
<tr>
<th class="firstCol" width="75%" style=""> E-mail address </th>
<th class="lastCol">Actions</th>
</tr>
<tr class="even">
<td>id@mailhost.com</td>
<td class="button">
<a onclick="deleteWhitelist('id@mailhost.com')" href="javascript:void(0)">Delete</a>
</td>
</tr>
</tbody>
</table>
</form>
<div id="whitelist-du-output" class="actionResult"></div>
<div class="subLink">
<a id="addNewEmailAddress" class="myk-link" href="javascript:void(0)" style="font-weight: normal;"> Add a new approved e-mail address </a>
</div>
</div>

Does anyone know how to execute addNewEmailAddress from perl .(I have already logged in using WWW::Mechanize).

user1092042
  • 1,297
  • 5
  • 24
  • 44
  • If you want to follow a link you need to use follow_link of www::mechanize ..Refer to this link for details http://search.cpan.org/~jesse/WWW-Mechanize-1.72/lib/WWW/Mechanize.pm#$mech-%3Efollow_link%28...%29 – Raghuram May 18 '12 at 04:18
  • I have tried that and even find_all_links but it does not show up. Probably because the add new email address is a javascript – user1092042 May 18 '12 at 04:53
  • Got your point. Can you check this link which says something about Javascript link http://search.cpan.org/~corion/WWW-Mechanize-Shell-0.52/lib/WWW/Mechanize/Shell.pm. Sorry,if the link is not useful – Raghuram May 18 '12 at 06:34
  • You can't execute `addNewEmailAddress` because that is an [HTML id](http://www.w3.org/TR/html4/struct/global.html#adef-id), not a JavaScript expression. -- Clarify: is the code you posted really the serialised DOM as returned from **Scripter**'s `content` method? – daxim May 18 '12 at 06:47
  • I get it. But i used firebug and this was what was printed. I really dont get how it works. Even the href does not point to an actual link. Once again the site is https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&ref_=gno_yam_myk#pdocSettings – user1092042 May 18 '12 at 07:25
  • Look at the DOM generated by WWW::Scripter, obviously there is an event attached to that `a` element. Learn about JS event handlers. - It makes no sense to post a link to a password-protected page. If you want people to help you, you must enable them to see the problem on their own. Either [reduce all HTML and JS until you have a minimal test-case](http://sscce.org), or give us everything as stand-alone files to [reproduce the functionality of that page off-line](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html#showmehow), or with Amazon's permission give credentials for a test account. – daxim May 18 '12 at 07:59
  • I am sorry but i thought if you had a amazon account you could login.Wont happen anymore.I took a different approach to this problem. I simply copied the headers generated in my firefox extension and try to replicate them. But i dont know how exactly to do that. I have posted a question.-http://stackoverflow.com/questions/10648754/how-do-i-simulate-this-particular-post-request-in-mechanize. Just as an addon- How do i look at the dom generated by the www::scripter. As when i used firebug i could not see it override onclick or any other event handler – user1092042 May 18 '12 at 08:05

1 Answers1

0

If you want to use Perl to add/submit (new) email address to this Amazon system, you have to first log in.

I believe that step you have already coded. Then you have to save cookies for further requests.


To submit email you need to call POST request to url:

https://www.amazon.com/gp/digital/fiona/du/add-whitelist.html/ref=kinw_myk_wl_add

and submit two parameters with this request:

  • sid (this is a session id you will find in cookies; example: 183-9522205-2962863)
  • newEmail (email address you want to submit; example: my@email.address.com)

Do not forget to encode those strings.

Check response code, has to be 200. Then read response text to check a value of success parameter.

You may need to add referer to this request. If so, then it should be:

https://www.amazon.com/gp/digital/fiona/manage?ie=UTF8&ref_=gno_yam_myk

Ωmega
  • 42,614
  • 34
  • 134
  • 203