@almenovr

Как получить контент группы Facebook?

<?php
header('Content-type: text/html; charset=utf-8');
require 'phpQuery.php';

function print_arr($arr){
    echo '<pre>' . print_r($arr, true) . '</pre>';
}

function get_content($url, $data = []){
    $ch = curl_init($url);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

$url_auth = 'https://www.facebook.com/login';
$url = 'https://www.facebook.com/groups/websarafan.ru';
$auth_data = [
    'email' => '',
    'pass' => '',
];

$data = get_content($url_auth, $auth_data);
$data = get_content($url);
var_dump($data);


В чем ошибка? Результат выдает пустую страницу.
  • Вопрос задан
  • 120 просмотров
Пригласить эксперта
Ответы на вопрос 1
megakor
@megakor
Go/PHP developer | Вконтакте
header('Content-type: text/html; charset=utf-8');

function print_arr($arr){
    echo '<pre>' . print_r($arr, true) . '</pre>';
}

function get_content($url, bool $isPost = false, $data = []){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if ($isPost) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    }
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
    curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36');
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

$url_auth = 'https://www.facebook.com/login';
$url = 'https://www.facebook.com/groups/websarafan.ru';
$auth_data = [
    'email' => '',
    'pass' => '',
];

$data = get_content($url_auth, true, $auth_data);
$data = get_content($url, false);
var_dump($data);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы