How to cut part of a “curl” answer

I have been having a look at this for a while but I haven't found any answer yet.

I've got a curl command to send a HTTP POST request to a server, then I have created a script called "tmg.sh" which looks like the next one:

#! /bin/bash
echo "There you go:"
sleep 3s
curl "http://tmg.xunta.gal/consulta-tarxeta?blah_blah_blah&numero=$1"
echo "Thanks!"

Right then, so when I write the next command on the terminal:

chmode u+x ./tmg.sh

Because for some reason even in root account if I don't do this, it returns: bash: ./tmg.sh: Permission denied, but anyway let's go on, after I have done that, when I write the following:

./tmg.sh NUMBER_GOES_HERE

That number is the variable, then I got this answer:

There you go:
<html code not relevant>
<div class="infoContido"><p>Non hai ningunha recarga para o n&uacute;mero de tarxeta introducido.</p></div>
<html code not relevant>
Thanks!

Right, here comes my question, how can I get just a part of the whole HTML code? I mean, I just want a part of the website, something like this:

Non hai ningunha recarga para o número de tarxeta introducido.

Also, I'd like to notice that as I get a full page, there are plenty of

,

... Is that possible, if it is, how should I edit my script to get just this part?

Thank you so much and have a lovely day!

-1
18.06.2017, 16:09
3 ответа

Если класс объекта div, который вы хотите, всегда будет infoContido, вы можете использовать pup командой вида:

curl "http://tmg.xunta.gal/consulta-tarxeta?blah_blah_blah&numero=$1" | pup "div.infoContido"
0
28.01.2020, 05:14

Отправить вывод curl в новый файл. Например, в вышеупомянутом случае.

curl "http://tmg.xunta.gal/consulta-tarxeta?blah_blah_blah&numero=$1" | tee -a /var/tmp/mycurl

Теперь все, что вам нужно сделать, это найти строку из этого нового файла.

cat /var/tmp/mycurl | grep Non hai ningunha recarga para o número de tarxeta introducido.
-2
28.01.2020, 05:14

Вы не объясняете, как должен быть идентифицирован нужный вам текст.

Если вам нужен только текст, попробуйте linksвместо:

#! /bin/bash
echo "There you go:"
sleep 3s
links -dump "http://tmg.xunta.gal/consulta-tarxeta?blah_blah_blah&numero=$1"
echo "Thanks!"

Если идентификатор строки "infoContido", это может быть решением:

#! /bin/bash
echo "There you go:"
sleep 3s
curl "http://tmg.xunta.gal/consulta-tarxeta?blah_blah_blah&numero=$1" | grep infoContido | cut -d\> -f2 
echo "Thanks!"
0
28.01.2020, 05:14

Теги

Похожие вопросы