Search code examples
bashpostcurlcommand-linedata-transfer

Curl get only a specific piece of data


I have been experimenting with curl on the command line recently and was wondering if the following is possible.

I did the following command:

curl --data "ToBinary=fubar" http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp

What I get back is the entire page with the appropriate response (a webpage with the data I want), but I only want a specific piece of data (0110011001110101011000100110000101110010).

Without additional processing, is there a way to get this information directly?


Solution

  • You should use a html parser to extract the binary string and I think that curl cannot do that. One of many alternatives is and its mojolicious module that lets you post the page and use a DOM parser to extract the content, like this:

    perl -Mojo -E '
        say p(q{http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp} 
            => form 
            => { ToBinary => q{fubar} })
        ->dom
        ->at(q{#ToText})
        ->text'
    

    It yields:

    0110011001110101011000100110000101110010