I wonder if anyone can help me, I have on my site, a few articles, I would like to edit, the articles are on three pages, with three articles per page, each having the url link article, so far I am a little stuck on automatically going through each article on each page and editing them(as the links are javascript, to select a field I understand it would something similar to $mech->field('nameoffield, $value); however suppose the selection was a scroll down menu? with javascript : something like <script scr=... JSActions=[variable,"response1",variable2,"response2"</script>), and then moving onto the next page and editing them, and the next page. So far this is what I have come up with:
#! perl\bin\perl use strict; use warnings; use Data::Dumper; use WWW::Mechanize; my $text ='My new article...'; my $text2 = 'My second article...'; my $text3 = 'My third article...'; my $start; my $mech1 = WWW::Mechanize->new( agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', cookie_jar => {}); $mech1->get("http://www.example.com"); $mech1->form(1); $mech1->field('username',"username"); $mech1->field('password',"password"); $mech1->click("login"); if ($mech1->success){ print "successfully logged on \n";} else{print +!$;} $mech1->follow_link( text_regex => qr/Articles/i );
#There are 3 articles per page all having the text_regex articles, one underneath the other for ($start=1;$start<=3;$start++) { #at this particular point I have 3 articles per page as stated(there are scroll down options to edit the articles or delete the articles, but they are in javascript as stated earlier), and there are 3 pages, I would like to edit the articles on the first page with the same text in $text, and the the next three articles on the next page with the text in $text2, and the next three articles on the last page with $text3, I am a little stuck :( on how to proceed from here. $mech1->click("Article1"); #I have 3 articles at this point, all having the link article, but three of them of different lines, one underneath the other, I would like to go through each of them, click on the edit article link(which is in javascript, as well as the delete article link, but I would like to select the edit article link) and submit it with the amended text in $text..$text2...$text3.
if( $mech1->success){print "success \n";} else{print !$;} $mech1->click("Edit article"); if( $mech1->success){print "Editing article \n";} else{print !$;} $mech1->field('text',"$text");
I would like to do this for each articles on each page, after clicking on the text_reg of articles(by selection of articles, however it is in javascript), then clicking on the edit button, and filling in the new text
$mech1->click("submit"); if ($mech1->success){ print "article successfully submitted \n";} else +{print !$;} }
Would appreciate any help

In reply to editing an article that also uses javascript with mechanize by coder57

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.