Scrappy::Session(3pm)

πŸ“¦
version 0.94112090 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Scrappy::Session β€” the manual page, but make it cute πŸ’–

okay bestie, so this is Scrappy::Session(3pm), straight out of the User Contributed Perl Documentation, and we're gonna get you fluent in it, no cap. 🫢


✨ NAME ✨

Scrappy::Session β€” Scrappy Scraper Session Handling πŸ’…

🌸 VERSION 🌸

version 0.94112090 β€” yes that's the actual version string, iconic, don't question it πŸ‘‘

πŸ¦‹ SYNOPSIS πŸ¦‹

#!/usr/bin/perl
use Scrappy::Session;

my  $session = Scrappy::Session->new;

    -f 'scraper.sess' ?
    $session->load('scraper.sess');
    $session->write('scraper.sess');

    $session->stash('foo' => 'bar');
    $session->stash('abc' => [('a'..'z')]);

like literally copy that vibe and you're already cooking πŸ“


πŸ’œ DESCRIPTION πŸ’œ

Scrappy::Session provides YAML-Based session file handling for saving recorded data across multiple execution using the Scrappy framework. so your scraper remembers stuff between runs. it's giving persistent memory, but make it YAML ✨

πŸŽ€ ATTRIBUTES πŸŽ€

here's the list of object attributes that every single Scrappy::Session instance is walking around with, periodt.

πŸ’« auto_save

the auto_save attribute is a boolean and it decides whether your stash data gets automatically saved to the session file on update. like, do you want it to just do the thing, or do you want to be in control? main character choice fr fr.

my  $session = Scrappy::Session->new;

    $session->load('scraper.sess');
    $session->stash('foo' => 'bar');

    # turn auto-saving off
    $session->auto_save(0);
    $session->stash('foo' => 'bar');
    $session->write; # explicit write

see how she turns it off and then writes on purpose? that's the explicit write, bestie 😌

πŸ’« file

the file attribute gets/sets the filename of the current session file. getter AND setter, she does both, versatile queen.

my  $session = Scrappy::Session->new;

    $session->load('scraper.sess');
    $session->write('scraper.sess.bak');
    $session->file('scraper.sess');

πŸ”₯ METHODS πŸ”₯

🌈 load

the load method reads in a session file, and it returns its data in the structure it was saved-in. same shape going in as coming out, we love consistency 🫢

my  $session = Scrappy::Session->new;
my  $data = $session->load('scraper.sess');

🌈 stash

the stash method accesses the stash object, which is the lil container used to store data that's gonna get written to the session file. it's the holding pen, the vibe vault πŸ’…

my  $session = Scrappy::Session->new;
    $session->load('scraper.sess');

    $session->stash('foo' => 'bar');
    $session->stash('abc' => [('a'..'z')]);
    $session->stash->{123} = [(1..9)];

not me using both the method-call style AND the hash-deref style in the same snippet β€” she contains multitudes 😭

🌈 write

the write method writes out a session file. it saves the data stored in the session stash and it returns the data written upon completion. so you get receipts, always ask for receipts 🧾✨

my  $session = Scrappy::Session->new;

    $session->stash('foo' => 'bar');
    $session->stash('abc' => [('a'..'z')]);
    $session->stash->{123} = [(1..9)];

my  $data = $session->write('scraper.sess');

πŸ‘‘ AUTHOR πŸ‘‘

Al Newkirk <awncorp@cpan.org> β€” shoutout to the author, absolute legend, no notes 🫑

This software is copyright (c) 2010 by awncorp.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

so basically: it's free, you can share it, you can remix it, same terms as Perl 5 itself. slay. πŸ’–

aaaand that's the whole page bestie!! this beauty was documented for perl v5.34.0 and the page is dated 2022-06-17, and the manual name is Scrappy::Session(3pm) in case you forgot where you were. now go stash something and write it out, i'm obsessed with you πŸ’…πŸ’–βœ¨πŸ¦‹πŸŒΈπŸŽ€

πŸ“¦ where this page comes from