A
A
almenovr2020-04-25 10:13:40
PHP
almenovr, 2020-04-25 10:13:40

How to set up parsing with a headless browser?

<?php
require 'phpQuery.php';
require_once('vendor/autoload.php');

use HeadlessChromium\BrowserFactory;
use HeadlessChromium\Input\Mouse;
use HeadlessChromium\Communication\Connection;
use HeadlessChromium\Communication\Message;

$browserFactory = new BrowserFactory("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
// starts headless chrome
$browser = $browserFactory->createBrowser([
    'headless'        => false,         // disable headless mode
    'windowSize' => [1920, 1000],
    'enableImages' => false,
    'sendSyncDefaultTimeout' => 30000000,
    'userDataDir' => 'C:\Users\rusya\Downloads\ospanel\domains\localhost\fbparser\www',
    'mouse' => false // will enable verbose mode
]);
$page = $browser->createPage();

$uri = 'https://www.facebook.com/groups/websarafan.ru/';
$page->navigate($uri)->waitForNavigation();

$evaluation = $page->evaluate('document.documentElement.innerHTML')->getReturnValue();
$doc = phpQuery::newDocument($evaluation);
$posts = $doc->find('.u_0_1m');
$browser->close();

echo $posts->length;


I can’t search for classes on the Facebook page, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-04-25
@dimonchik2013

does it work with the head?

E
Eugene, 2020-04-25
@Nc_Soft

Set headless to true and see what it opens at all.
Also debug the $evaluation variable to see if the html is correct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question