T
T
tyoma_koder2021-07-18 16:26:06
PHP
tyoma_koder, 2021-07-18 16:26:06

How to work with curl?

I want to parse products from a third-party site, I used file_get_content, the html of the page was returned, but I found out that there is a more correct way - curl, but the code below returns a 301 redirect, namely the text in the picture.
How to get the html of the page in such a way that you can use selectors, or at least in the form of an associative array?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.vashidveri72.ru/catalog/dveri_vkhodnye');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);

60f42b9405554004367450.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-sem, 2021-07-18
@tyoma_koder

Need to add
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question