A
A
almenovr2020-04-21 12:41:05
PHP
almenovr, 2020-04-21 12:41:05

How to get Facebook group content?

<?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);


Where is the mistake? The result is a blank page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2020-04-21
@megakor

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);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question