Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created August 28, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/0f54957ea784dc52e43cee0e0766c0ff to your computer and use it in GitHub Desktop.
Save zoffixznet/0f54957ea784dc52e43cee0e0766c0ff to your computer and use it in GitHub Desktop.
use WWW;
use DOM::Tiny;
constant URL = 'https://www.ncbi.nlm.nih.gov/pubmed';
constant OUT_FILE = 'results.txt'.IO;
sub make-term (:$term, :$year) {
'(' ~ $term ~ ' AND (("' ~ $year ~ '/01/01"[PDat] : "' ~ $year ~ '/12/31"[PDat])))'
}
my @terms = "terms.txt".IO.lines;
for @terms -> $term {
say "Doing searches for $term";
for 1990..2000 -> $year {
print "\t...year $year ";
my $results-num = DOM::Tiny.parse(post URL, term => make-term :$term, :$year)
.at('meta[name="ncbi_resultcount"]').attr: 'content';
say "Found $results-num results";
OUT_FILE.spurt: :append, "$year,$term,$results-num\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment