Using Chromium Cookies in a perl script -
i'm trying write perl script connect website , having issues storing cookies i'm grabbing out of chromium sqlite database. here's relevant code snippet:
use http::cookies; use data::dumper; use feature 'say'; use dbi; $cookie_jar = http::cookies->new(); $dbh = dbi->connect("dbi:sqlite:dbname=/home/{user}/.config/chromium/default/cookies", "", ""); $sth = $dbh->prepare("select * cookies host_key='{domain}'"); $sth->execute(); $rows; while ($rows = $sth->fetch()) { dumper($rows); $cookie_jar->set_cookie(@$rows[0], @$rows[1], @$rows[2], @$rows[3], @$rows[4], @$rows[5], @$rows[6], @$rows[7], @$rows[8], @$rows[9]); dumper($cookie_jar); } $sth->finish(); $dbh->disconnect(); dumper($cookie_jar);
i scrubbed username , domain "say dumper($rows)" statement returning cookie information i'm expecting. thus, know sqlite database access working. "say dumper($cookie_jar)" both inside , outside while loop returning empty cookie_jar. i've started playing around perl there i'm missing when comes setting data?
i found there no standard cookie values or standard order store them. fields 0-9 in chromium cookies not map fields 0-9 in http::cookies. seems set_cookie method failing because of weird values not being verbose errors. realized better way approach use hashrefs rows i'd have more readable code:
# set_cookie($version, $key, $val, $path, $domain, # $port, $path_spec, $secure, $maxage, $discard, \%rest ) while ($rows = $sth->fetchrow_hashref()) { $cookie_jar->set_cookie(0, $rows->{name}, $rows->{value}, $rows->{path}, $rows->{host_key}, 443, 0, $rows->{secure}, 1000000, 0); dumper($cookie_jar); }
i've added set_cookie values in comments make method more obvious other people adapting own purposes.
Comments
Post a Comment