W3docs

How to get page content using cURL?

To get the content of a webpage using cURL, you can use the following command:

To get the content of a webpage using cURL, you can use the following command:

Example of getting page content using cURL in the terminal

curl https://example.com

This will retrieve the content of the webpage and print it to the terminal.

If you want to save the content to a file, you can use the -o flag to specify an output file:

curl https://example.com -o output.html

This will save the content of the webpage to a file called output.html.

You can also use the -L flag to follow redirects, if the webpage you are trying to access is redirected to another location:

curl https://example.com -L

This will follow any redirects and retrieve the content of the final webpage.

Example of getting page content using cURL in PHP

$ch = curl_init('https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
echo $content;

You can find more information and options for the cURL command by typing man curl or by visiting the cURL documentation online.