Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to find a Terminal command that can pull the file at http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=SOMEUSERNAME&count=1 and parse it to find a user's Twitter status. The status is inside the "statuses -> status -> text" location on the tree.

I've looked into libxml and xmllint. I think I'm on the right track with xmllint, but I'm not sure. With xmllint, I know I could do xmllint --shell file.xml and then cat //statuses/status/text. But, I'd prefer to be able to do some type of command like CURL | XMLLINT | SED that would download the file, parse it, and return the status in one fell swoop.

share|improve this question
    
Take a look at this –  soandos Aug 18 '11 at 19:20
add comment

1 Answer

up vote 2 down vote accepted

Perl's XML::Twig comes with...

xml_grep --nowrap --text_only /statuses/status/text

In XML::XPath you can do:

perl -MXML::XPath -E 'my $xp = XML::XPath->new(ioref => \*STDIN); say $xp->getNodeText("/statuses/status/text");'

or

perl -MXML::XPath -E 'my $xp = XML::XPath->new(ioref => \*STDIN); for my $node ($xp->find("/statuses/status/text")->get_nodelist) { say $node->string_value; }'

(Of course, there's Net::Twitter too.)

share|improve this answer
1  
I've found Net::Twitter::Lite easier to work with for simple stuff –  charlesbridge Aug 19 '11 at 11:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.