Очистка данных с использованием php curl и прокси - PullRequest
0 голосов
/ 05 сентября 2018

Я использую приведенный ниже скрипт для очистки данных, когда я захожу на страницу php, он работает только с несколькими веб-сайтами, такими как Google, для остальных это будет просто пустая страница. Есть ли проблема с кодом? и как его отладить?

<?php

$request = curl_init("https://www.google.com");
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer 31d15a'
));

$response = curl_exec($request);
echo $response;
curl_close($request);

1 Ответ

0 голосов
/ 05 сентября 2018

Возможны дополнительные параметры, но для вашей задачи может быть достаточно следующих.

//Initialise Curl
$ch = curl_init();

//set the url to be used
curl_setopt($ch, CURLOPT_URL, $url);

//follow HTTP 3xx redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//automatically update the referer header
curl_setopt($ch, CURLOPT_AUTOREFERER, true);

//accept the responce after the execution
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//don't verify the peer's SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//set the browser
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

//executes given cURL session.
$html = curl_exec($ch);

//disable libxml errors
libxml_use_internal_errors(TRUE); 

//closes Curl session, & frees up the associated memory
curl_close($ch);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...