My signature had a line in <pre> that was very long and messing up the PM layout for some. Good excuse to use WWW::Mechanize again :)

#!/usr/bin/perl -wl use strict; use Carp; use WWW::Mechanize; use HTML::TreeBuilder; { my $i; sub x { shift() ? print ++$i : croak } } my $sig = q[ Juerd # { site => '<a href="http://juerd.nl/" target="_blank"><font color="# +800000">juerd.nl</font></a>', plp_site => '<a href="http://plp.juerd. +nl/" target="_blank"><font color="#800000">plp.juerd.nl</font></a>', +do_not_use => '<a href="mailto:spamcollector_perlmonks@juerd.nl" targ +et="_blank"><font color="#800000">spamtrap</font></a>' } ]; x my $agent = WWW::Mechanize->new; x $agent->get('http://perlmonks.org/index.pl?node=login'); x $agent->submit_form( form_number => 2, fields => { user => 'Juerd', passwd => '', # Guess =) }, button => 'sexisgood', ); x $agent->get('http://perlmonks.org/index.pl?node_id=6364&user=Juerd') +; my $tree = HTML::TreeBuilder->new_from_content($agent->content); for ($tree->look_down(id => 'writeups')->look_down(_tag => 'a')) { x my $href = $_->attr('href'); x my ($node_id) = $href =~ /node_id=(\d+)/; next if $node_id < 253475; # 253475 was the first node with the n +ew sig x $agent->get($href); x $agent->form_number(2); my $post = eval { $agent->current_form->value('note_doctext'); } or next; $post =~ s[<pre>(.*?)</pre>][$sig]s; x $agent->submit_form( form_number => 2, fields => { note_doctext => $post }, button => 'sexisgood', ); }

There were less than 50 nodes to be fixed, so I didn't have to fetch other pages. And this script only works for notes :)

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


In reply to Scraping PerlMonks by Juerd

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.