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ú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 Thank you so much and have a lovely day! ,
Отправить вывод 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.
Вы не объясняете, как должен быть идентифицирован нужный вам текст.
Если вам нужен только текст, попробуйте 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!"