diff options
author | emkael <emkael@tlen.pl> | 2019-06-13 00:29:38 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-06-13 00:29:38 +0200 |
commit | cf27fd41f2cf3a61e7103a2311f123b0035fbf9c (patch) | |
tree | ac3f096bcfa374823d5a1740ec0cad8677359d6e /providers | |
parent | 116b5b8d761c91fe2fb756364e94632841716398 (diff) |
Fuck off, Facebook
Diffstat (limited to 'providers')
-rw-r--r-- | providers/Facebook.php | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/providers/Facebook.php b/providers/Facebook.php index 393b7b7..ed9f8f1 100644 --- a/providers/Facebook.php +++ b/providers/Facebook.php @@ -24,45 +24,43 @@ class Facebook extends \Providers\HtmlFeed { } protected function _getFeedUrl($feed) { - return sprintf('https://m.facebook.com/%s', $feed); - } - - protected function __getUserAgent() { - return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.1'; + return sprintf('https://m.facebook.com/%s/posts', $feed); } protected function _parseFeedContent($tree) { + $items = []; if (isset($this->_options['dump'])) { print($tree->html()); - die(); } - $items = []; - foreach ($tree->find('div[data-ft]') as $div) { - $data = json_decode($div->attr()['data-ft'], TRUE); - if (isset($data['mf_story_key'])) { - $pIns = $data['page_insights'][$data['page_id']]; - $key = $data['mf_story_key']; - $texts = []; - foreach ($div->find('h3') as $h3) { - if (!$h3->find(sprintf('a[href^="/%s/"]', $this->_feed))->count() || $h3->find('a')->count() > 1) { - $texts[] = trim($h3->text()); - } - } - foreach ($div->find('div>span p') as $p) { - $texts[] = trim(strip_tags($p->html())); - } - foreach ($div->find('div[data-ft]>div[style] span[style]>span') as $p) { - $texts[] = trim(strip_tags($p->html())); - } - if (count($texts)) { - $items[$key] = [ - 'id' => $key, - 'content' => $div->html(), - 'texts' => $texts, - 'time' => $pIns['post_context']['publish_time'] - ]; - } + foreach ($tree->find('article') as $header) { + $data = json_decode($header->attr()['data-store'], TRUE)['linkdata']; + $data = array_filter( + json_decode(explode('page_insights.', $data)[1], TRUE), + function($a) { return isset($a['post_context']); } + )['post_context']; + $key = $data['story_fbid']; + $texts = []; + foreach ($header->find('p, h3') as $paragraph) { + $texts[] = $paragraph->text(); } + if (isset($this->_options['dump'])) { + print_r($data); + print($key); + print(PHP_EOL); + print_r($texts); + print(PHP_EOL); + } + if (count($texts)) { + $items[$key] = [ + 'id' => $key, + 'time' => $data['publish_time'], + 'content' => $header->html(), + 'texts' => $texts + ]; + } + } + if (isset($this->_options['dump'])) { + die(); } return array_values($items); } |