Skip to content

Instantly share code, notes, and snippets.

@sestaton
Last active December 26, 2015 19:18
Show Gist options
  • Save sestaton/7200050 to your computer and use it in GitHub Desktop.
Save sestaton/7200050 to your computer and use it in GitHub Desktop.
biostars84811.pl - get pubmed abstract
#!/usr/bin/env perl
use 5.010;
use utf8;
use strict;
use warnings;
use Bio::DB::EUtilities;
use XML::LibXML;
my @ids = (23298400);
my $factory = Bio::DB::EUtilities->new(-eutil => 'efetch',
-email => 'mymail@foo.bar',
-db => 'pubmed',
-retmode => 'xml',
-id => \@ids);
my $xml = $factory->get_Response->content;
my $xml_parser = XML::LibXML->new();
my $dom = $xml_parser->parse_string($xml);
my $root = $dom->documentElement();
for my $node ($root->findnodes('//*[text()]')) {
my $name = $node->nodeName();
if ($name eq 'Abstract') {
for my $child ($node->findnodes('*')) {
binmode STDOUT, ":utf8";
say $child->textContent();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment