user1577303
user1577303

Reputation:

Get part of webpage with cURL

So what I'm doing now is getting all the webpage that curl returns from the request I make. What I'm looking for is to make curl download only a part from that page in order to speed things up a bit, something like from character n to character m of the webpage. Is there any way to do this? Maybe not with curl?
Thanks.
Edit: So if the server doesn't support a range request, can I get only from the first character until some n character and stop downloading?

Upvotes: 1

Views: 1730

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 57994

Yes it is possible with a HTTP range request - if the server allows it. curl supports that with the -r or --range option. Like if you want byte index 15 to and including byte index 29 from a URL:

curl -r 15-29 http://example.com

If the server doesn't support byte ranges (common when the server generates the response dynamically), an easy approach is to just pipe the output to head and have that stop at the suitable point:

curl -s http://example.com | head --bytes=100 > output

Upvotes: 1

Related Questions