3

Is it possible to grep a string on a URL, which is 301 Moved Permanently? For example on this URL:

https://eshop.unihobby.cz/zahrada-zimni-sortiment-vanoce-vanocni-osvetleni-interierove-osvetleni-vanocni-led-osvetleni-100ks-8-programu-barevna-bila-vnitrni/142117p/

I need to grep a string using curl

Litujeme, ale stránka nebyla nalezena

I tried via curl, but it shows me only this, no such string is present.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://eshop.unihobby.cz/bydleni-prani-a-zehleni-zehlici-prkna-zehlici-prkno-airboard-premium-leifheit/130475p/">here</a>.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at eshop.unihobby.cz Port 80</address>
</body></html>
4

It's not very clear what you are asking but in case you want curl to follow redirects, you can do the following:

Tell curl to follow redirects:

In curl's tradition of only doing the basics unless you tell it differently, it does not follow HTTP redirects by default. Use the -L, --location to tell it to do that.

When following redirects is enabled, curl will follow up to 50 redirects by default. There's a maximum limit mostly to avoid the risk of getting caught in endless loops. If 50 is not sufficient for you, you can change the maximum number of redirects to follow with the --max-redirs option.

Syntax:

curl -L <URL> | grep "<your-search-term>"

So, you should use:

curl -L https://eshop.unihobby.cz/zahrada-zimni-sortiment-vanoce-vanocni-osvetleni-interierove-osvetleni-vanocni-led-osvetleni-100ks-8-programu-barevna-bila-vnitrni/142117p/ | grep "Litujeme, ale stránka nebyla nalezena"
| improve this answer | |
  • 1
    @Akshay Anurag Magic, thanks. :) Just detail, you need use -s parameter too, so result is curl -s -L <url> | grep "<your-search-here>". Thanks again. – Stanislav Hosek Jul 24 '19 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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