How can I handle UTF-8 while posting to a vBulletin board with WWW::Mechanize?

Posted by MrMirror on Stack Overflow See other posts from Stack Overflow or by MrMirror
Published on 2010-03-18T16:06:37Z Indexed on 2010/03/22 16:41 UTC
Read the original article Hit count: 474

Filed under:
|
|
|
|

I have a problem with some automating posting to bulletin board... If I send the posting form to the vBulletin board, I get corrupted entities.

Feel free to copy-paste the script and try it...

It looks like the board's expecting some decoded utf8, but if I send the message decoded the entities are still wrong.

#!/usr/bin/perl

use strict;
use warnings;

use WWW::Mechanize;
use Digest::MD5 qw(md5_hex);

my $mech = WWW::Mechanize->new();

my $base_url = 'http://www.boerse.bz/';

my $username = 'MrMirror';
my $password = 'test';

$mech->get($base_url);

print "Login\n";

$mech->form_number(1);
$mech->field('vb_login_username' => $username);
$mech->field('vb_login_password' => $password);
$mech->field('vb_login_md5password' => md5_hex($password));
$mech->field('vb_login_md5password_utf' => md5_hex($password));
$mech->submit();

unless ($mech->content() =~ m!Weiterleitung!gi)
{
    print "No Rediction!\n";
    exit;
}

print "Redict\n";

$mech->get($base_url);

unless ($mech->content() =~ m!Logout!gi)
{
 print "Login Failed!\n";
    exit;
}

$mech->get($base_url .'/newthread.php?do=newthread&f=173');

$mech->form_number(3);
$mech->field('subject' => 'MrMirror makes some testing ä ö ü ß');
$mech->field('message' => "ä ö ü ß");

### everything allright here
$mech->dump_forms();

### preview submit, don't wanna spam around ;)
$mech->click('preview');
print "\n\n\n---------------------------------------------------------------------\n\n\n";

### same form, wrong entities :(
$mech->dump_forms();

© Stack Overflow or respective owner

Related posts about www

Related posts about mechanize