Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. use WWW;
  2. use DOM::Tiny;
  3. use URI::Encode;
  4.  
  5. constant URL = 'https://www.ncbi.nlm.nih.gov/pubmed';
  6. my $fh = open :w, 'results5.txt';
  7. constant OUT_FILE = 'results5.txt'.IO;
  8.  
  9. sub make-term (:$term, :$year) {
  10. '(' ~ $term ~ '[Title/Abstract] AND united states[pl] AND (("' ~ $year ~ '/01/01"[PDat] : "' ~ $year ~ '/12/31"[PDat])))'
  11. }
  12.  
  13. my @terms = "list5.txt".IO.lines.map: *.subst(:g, " ", "+").&uri_encode;
  14. my $id = 2135;
  15.  
  16. for @terms -> $term {
  17. $id = $id + 1;
  18. say "Doing searches for $term";
  19. for 1966..2016 -> $year {
  20. print "\t...year $year ";
  21. my $results-num = DOM::Tiny.parse(post URL, term => make-term :$term, :$year)
  22. .at('meta[name="ncbi_resultcount"]').attr: 'content';
  23. say "Found $results-num results";
  24. OUT_FILE.spurt: :append, "$id,$term,$year,$results-num\n";
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement