Created
November 12, 2015 21:14
-
-
Save Skarsnik/65af8fd9fd898ff6eb2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
if (@pages.elems eq 1) { | |
$number_of_page = 1; | |
} else { | |
$number_of_page = @pages[@pages.elems-2][0][0].text; | |
} | |
say "Number of page : $number_of_page"; | |
for (1..$number_of_page) { | |
$rep = $ua.get("$url?order=date_added&page=$_"); | |
if ! $rep.is-success { | |
die "can't get $url?order=date_added&page=$_"; | |
} | |
my $innerdiv = parse-html($rep.content, :TAG<div>, :class<inner>, :SINGLE, :nowhitespace); | |
if $_ == 1 { | |
my $ul = $innerdiv.elements(:TAG<span>, :class<bookshelf-name>, :SINGLE, :RECURSE); | |
$bookshelf.name = $ul[0][0].text; | |
} | |
my @storydiv = $innerdiv.lookfor(:TAG<div>, :class<story_content_box>); | |
for @storydiv -> $storydiv { | |
my $idstory = substr($storydiv<id>, 6); | |
my Story $story = get_story($idstory.Int); | |
my $extradiv = $storydiv.lookfor(:TAG<div>, :class<extra_story_data>, :SINGLE); | |
my @charactera = $extradiv.lookfor(:TAG<a>, :class<character_icon>); | |
for @charactera -> $aelem { | |
$story.character_tags.push($aelem<title>); | |
} | |
say $story.title; | |
#show_mem(); | |
$bookshelf.stories.push($story); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment