$url = 'https://www.facebook.com/marketplace/106039436102339/electronics/';
$options = [
'http'=> [
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0',
'protocol' => 1.1,
'header' => [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Upgrade-Insecure-Requests: 1',
'Host: www.facebook.com',
]
]
];
$context = stream_context_create($options);
$html = file_get_contents($url, false, $context);
{
"__typename": "GroupCommerceProductItem",
"id": "2847931948807724", // страница товара `https://www.facebook.com/marketplace/item/{id}/`
"primary_listing_photo": {
"__typename": "Photo",
"image": {
"uri": "https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-0\/c43.0.260.260a\/p261x260\/126459943_3501983189884214_6730841962174251261_n.jpg?_nc_cat=111&ccb=2&_nc_sid=3b2858&_nc_ohc=omsCjvSdK-sAX91cBu0&_nc_ht=scontent.xx&tp=27&oh=1fedfb95e4d2fbd45a94cfdeb4aafe54&oe=6025F841"
},
"id": "3501983176550882"
},
"__isMarketplaceListingRenderable": "GroupCommerceProductItem",
"formatted_price": {
"text": "\u20ac20"
},
"location": {
"reverse_geocode": {
"city": "Tallinn",
"state": "",
"city_page": {
"display_name": "Tallinn, Estonia",
"id": "106039436102339"
}
}
},
"is_hidden": false,
"is_live": true,
"is_pending": false,
"is_sold": false,
"is_viewer_seller": false,
"min_listing_price": null,
"max_listing_price": null,
"marketplace_listing_category_id": "1792291877663080",
"marketplace_listing_title": "KOHE OLEMAS - UUED juhtmevabad k\u00f5rvaklapid bluetooth airpods pods",
"custom_title": null,
"custom_sub_titles_with_rendering_flags": [],
"origin_group": null,
"pre_recorded_videos": [],
"__isMarketplaceListingWithChildListings": "GroupCommerceProductItem",
"parent_listing": null,
"__isMarketplaceListingWithDeliveryOptions": "GroupCommerceProductItem",
"delivery_types": ["IN_PERSON"]
}
$options = [
'http'=> [
'follow_location' => 1,
'user_agent' => 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0',
//'proxy' => '',
]
];
$context = stream_context_create($options);
$url = "https://www.facebook.com/marketplace/category/electronics/";
$html = file_get_contents($url, false, $context);
Marketplace недоступен для вас
Это сообщение показывается, если вы на Facebook недавно, Marketplace пока не поддерживается в вашей стране или ваш аккаунт не отвечает нашим требованиям. Подробнее см. в нашем Справочном центре.
<?php
class LigaAPI
{
const BASE_URL = 'http://fantasyland.ru/cgi/';
/**
* @var resource Дескриптор cURL соединения
*/
protected $handler;
/**
* @var bool Игрок авторизован?
*/
protected $logged = FALSE;
/**
* @var int Текущее местоположение игрока
*/
protected $place = 0;
/**
* @var int Текущая локация игрока
*/
protected $location = 0;
/**
* @var array Места на карте
*/
protected $places = array(
2 => 'Столица',
3 => 'Лагерь Наемников',
4 => 'Замок Паладинов',
5 => 'Шахты',
6 => 'Илдиор',
7 => 'Лагденойский Лес',
9 => 'Башня Хаоса',
11 => 'Ведьмины Топи',
12 => 'Торговый Порт',
13 => 'Долина Магов',
14 => 'Лесной Замок',
16 => 'Горный Замок',
17 => 'Руины',
18 => 'Пещеры Драконов',
19 => 'Башня Смерти',
20 => 'Болотный Замок',
23 => 'Пустынный Замок',
25 => 'Каменный Клык',
26 => 'Лотариель',
27 => 'Маковый Лес',
33 => 'Заброшенная Ферма',
);
/**
* @var array Локации на местах
*/
protected $locations = array();
/**
* Инициализация параметров объекта
*
* @return void
*/
public function __construct()
{
// Инициализация соединения
$this->handler = curl_init();
// Создать файл для хранения куки
if (! is_file('cookie_liga_api'))
{
file_put_contents('cookie_liga_api', '');
}
// Основные настройки соединения
$options = array(
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0',
CURLOPT_COOKIEFILE => 'cookie_liga_api',
CURLOPT_COOKIEJAR => 'cookie_liga_api',
CURLOPT_CONNECTTIMEOUT => 5,
);
curl_setopt_array($this->handler, $options);
if (! isset($_SESSION))
{
session_start();
}
if (isset($_SESSION['liga_api']))
{
list($this->place, $this->location, $this->locations) = $_SESSION['liga_api'];
$this->logged = TRUE;
}
}
/**
* Закрытие соединения при завершении работы
*
* @return void
*/
public function __destruct()
{
curl_close($this->handler);
}
/**
* Получение контента страницы
*
* @return string
* @throws Exception
*/
public function request($url, array $post = array())
{
$options = array(
CURLOPT_URL => self::BASE_URL . $url,
CURLOPT_POST => ! empty($post),
CURLOPT_POSTFIELDS => $post,
);
curl_setopt_array($this->handler, $options);
$response = curl_exec($this->handler);
if ($response === FALSE)
{
throw new Exception(__METHOD__ . ' ' . $url . ': ' . curl_error($this->handler));
}
return iconv('Windows-1251', 'UTF-8', $response);
}
/**
* Получение и парсинг контента страницы
*
* @return array
*/
public function parse($text, $regex, $all = FALSE)
{
if ($all)
{
preg_match_all('#' . $regex . '#muU', $text, $matches, PREG_SET_ORDER);
}
else
{
preg_match('#' . $regex . '#muU', $text, $matches);
}
return (array) $matches;
}
/**
* Авторизация в игре
*
* @return this
*/
public function login($login, $password)
{
if (! $this->logged)
{
$this->request('../login.php', compact('login', 'password'));
$this->logged = TRUE;
$_SESSION['liga_api'] = array(
'place' => $this->place,
'location' => $this->location,
'locations' => $this->locations,
);
}
return $this;
}
/**
* Выйти из игры
*
* @return this
*/
public function logout()
{
if ($this->logged)
{
$this->request('exit.php');
$this->logged = FALSE;
unset($_SESSION['liga_api']);
}
return $this;
}
/**
* Авторизация в игре
*
* @return this
*/
public function loadInfo()
{
$response = $this->request('loc_list.php');
list(, $this->place, $this->location) = $this->parse($response, 'curPlace=([\d]+); curLoc=([\d]+);');
$filename = 'locations_' . $this->place . '.php';
if (is_file($filename))
{
$this->locations = include $filename;
}
else
{
$data = $this->parse($response, "push\(\['([^']+)', ([\d]+)\]", TRUE);
foreach ($data as $value)
{
$this->locations[$value[2]] = str_replace(' ', ' ', $value[1]);
}
file_put_contents($filename, '<?php return ' . var_export($this->locations, TRUE) . ';');
}
$_SESSION['liga_api'] = array(
'place' => $this->place,
'location' => $this->location,
'locations' => $this->locations,
);
return $this;
}
/**
* Перейти в локацию
*
* @return string
*/
public function loadLocation($location = NULL)
{
if (is_null($location))
{
// Load current location
return $this->request('no_combat.php');
}
if (! $this->locations)
{
$this->loadInfo();
}
if (! in_array($location, $this->locations))
{
throw new Exception(__METHOD__ . ' location ' . $location . ' not exist');
}
$location = array_search($location, $this->locations);
$response = $this->request('no_combat.php', array('locat' => $location, 'additional' => 0));
$_SESSION['liga_api']['location'] = $this->location = $location;
return $response;
}
/**
*
*
* @return string
*/
public function getPlace()
{
if (! $this->place)
{
$this->loadInfo();
}
return $this->places[$this->place];
}
/**
*
*
* @return string
*/
public function getLocation()
{
if (! $this->location)
{
$this->loadInfo();
}
return $this->locations[$this->location];
}
}
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/?foo=bar');
xhr.withCredentials = true;
xhr.onreadystatechange = function() {
if (xhr.readyState === xhr.HEADERS_RECEIVED) {
// ну и дальше сохраняй строку с печенькой
var cookies = xhr.getResponseHeader('Cookie');
// чтобы не грузить лишний контент
xhr.abort();
}
}
xhr.send();