Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

Unless you can convince the author to provide an api that returns just the converted data, you can't do it without extra processing. An alternative is to do it yourself.

ascii to binary text:

echo fubar | perl -pe 's/(.)/sprintf("%08b", ord($1))/eg'

binary text to ascii:

echo 0110011001110101011000100110000101110010 | \
perl -pe 's/([01]{8})/sprintf("%s", pack("B8", $1))/eg'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top