Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 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, 'results.txt';
  7. constant OUT_FILE = 'results.txt'.IO;
  8.  
  9. #sub make-term (:$term, :$year) { #'(' ~ $term ~ ' AND (("' ~ $year ~ '/01/01"[PDat] : "' ~ $year ~ '/12/31"[PDat])))' }
  10. sub make-term (:$term, :$year) {
  11. '(' ~ $term ~ '[Title/Abstract] AND united states[pl] AND (("' ~ $year ~ '/01/01"[PDat] : "' ~ $year ~ '/12/31"[PDat])))'
  12. }
  13.  
  14. my @terms = "list.txt".IO.lines.map: &uri_encode;
  15. my $id = 0;
  16.  
  17. for @terms -> $term {
  18. $id = $id + 1;
  19. say "Doing searches for $term";
  20. for 1966..2016 -> $year {
  21. print "\t...year $year ";
  22. my $results-num = DOM::Tiny.parse(post URL, term => make-term :$term, :$year)
  23. .at('meta[name="ncbi_resultcount"]').attr: 'content';
  24. say "Found $results-num results";
  25. OUT_FILE.spurt: :append, "$id,$term,$year,$results-num\n";
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement