Skip to content

Instantly share code, notes, and snippets.

use v6;
use Gumbo;
use XML;
use HTTP::UserAgent;
#We define some base url, notice that I don't use https
my $bbaseurl = "http://www.fimfiction.net/bookshelf/";
my $fimbaseurl = "http://www.fimfiction.net/";
use v6;
use lib './', '/root/testmodif/s/perl6-html-parser-xml/lib/';
use FicClass;
use Gumbo;
use StoryFactory;
use HTTP::UserAgent;
use HTTP::Cookie;
use Gumbo::Parser; # replace with HTML::Parser::XML
use XML;
my $parser = Gumbo::Parser.new;
my $html = qqx{wget -o /dev/null -O - https://www.fimfiction.net/bookshelf/149291/};
say "Getting/parsing a wegpage with a quite huge xml tree, prepare yourself some coffee if you use H:P:X";
say "webpage is "~$html.chars~" size.";
my $xml = $parser.parse($html);
use Config::Simple::Role;
class Config::Simple does Config::Simple::Role {
multi method new($filename) {
return self.bless(:filename($filename));
}
multi method new($filename, Str :$b) {
my $module = "Config::Simple::$b";
sub get_bookshelf {
my $rep = $ua.get("$bbaseurl$bookid");
if ! $rep.is-success {
die "Can't contact $bbaseurl";
}
# first we need to know the number of page
my $xmldoc = parse-html($rep.content, :TAG<div>, :class<page_list>, :SINGLE, :nowhitespace);
my @pages = $xmldoc.elements(:TAG<li>, :RECURSE);
my $number_of_page;