title: Extract public posts from Facebook page without API/APP key/token/secret
body: <p>Just to clarify in advance, I don't have a Facebook account and I have no intent to create one. Also, what I'm trying to achieve is perfectly legal in my country and the USA.</p>
  
  <p>Instead of using the Facebook API to get the latest timeline posts of a Facebook page, I want to send a get request directly to the page URL (e.g. <a href="https://www.facebook.com/pg/officialstackoverflow/posts/" rel="noreferrer">this page</a>) and extract the posts from the HTML source code.<br>
  (I'd like to get the text and the creation time of the post.)  </p>
  
  <p>When I run this in the web console:</p>
  
  <pre><code>document.getElementsByClassName('userContent')
  </code></pre>
  
  <p>I get a list of elements containing the text of the latest posts. </p>
  
  <p>But I'd like to extract that information from a nodejs script. I could probably do it quite easily using a headless browser like <code>puppeteer</code> or the like, but that would create a ton of unnecessary overhead. I'd really like to a simple approach like downloading the HTML code, passing it to cheerio and use cheeriio's jQuery-like API to extract the posts. </p>
  
  <p>Here is my attempt of trying exactly that:</p>
  
  <pre><code>// npm i request cheerio request-promise-native
  const rp = require('request-promise-native'); // requires installation of `request`
  const cheerio = require('cheerio');
  
  rp.get('https://www.facebook.com/pg/officialstackoverflow/posts/').then( postsHtml =&gt; {
      const $ = cheerio.load(postsHtml);
  
      const timeLinePostEls = $('.userContent');
      console.log(timeLinePostEls.html()); // should NOT be null
      const newestPostEl = timeLinePostEls.get(0);
      console.log(newestPostEl.html()); // should NOT be null
      const newestPostText = newestPostEl.text();
      console.log(newestPostText);
      //const newestPostTime = newestPostEl.parent(??).child('.livetimestamp').title;
      //console.log(newestPostTime);
  }).catch(console.error);
  </code></pre>
  
  <p>unfortunately <code>$('.userContent')</code> does not work. However, I was able to verify that the data I'm looking for is embedded somewhere in that HTML code.</p>
  
  <p>But I couldn't really come up with a with a good regex approach or the like to extract that data.</p>
  
  <p>Depending on the post content the number of HTML tags within the post varies heavily. </p>
  
  <p>Here is a simple example of a post containing one link:</p>
  
  <pre><code>&lt;div class="_5pbx userContent _3576" data-ft="&amp;#123;&amp;quot;tn&amp;quot;:&amp;quot;K&amp;quot;&amp;#125;"&gt;&lt;p&gt;We&amp;#039;re proud to be named one of Built In NYC&amp;#039;s Best Places to Work in 2019, ranking in the top 10 for Best Midsize Places to Work and top 3 (!) for Best Perks and Benefits. See what it took to make the list and check out our profile to see some of our job openings. &lt;a href="https://l.facebook.com/l.php?u=https%3A%2F%2Fbit.ly%2F2H3Kbr2&amp;amp;h=AT29h2HyDsEk0rHRWqJA-Fa4M1qi3nJT1NBi95othaR3qeFuFAMNiVS2Dgtv5KR5m0xqjw6kfwZdhZt0_D3UQT1Oel2UhxRql-KwkA1xqWvrql4u1jDhzrkGVT_XxoUd8_w8_fzLZzzhz23a8yPCK6IPfWKB76_CEFjG3b78y4dFJvY9Z08AYlR01dmi5_FvWVEVytkN-123u6alYE8pqL6Jb6dtIQUTWGXYJPaNMrtxkCUZniEVXEcILkwHGSuHqCTAarboyMP55F1vhYO3OAiVMkvjbN274fVq92YvbK3bi90bU9T-5ADWHDUJ-CwcofSBTW47chstQeY0n_UluD_rBIPLsfXVSnCtpRkR2kXi9zzHLnNeIYeNssv3i7UKS_f5Z2pnVT6xe3zJbNpB68doH1Z__I9nsTCNIyFyKx2VxabecoL03DIawbRrzBoxLAwzNPLACBjTkpEQhdVn4_wdAIjXRL4cLQDcZkLEoG_sspBgRePH23TFbNufQOBly-FNtLHnkUDO2Ca-FYvAGXpcu6J4B1aH3XFPB803lsz-GRdACyOFOgXDXJfwr4WtWzUHxfiOPULWiI43yI5L4aU6wYRhPjxua3RuRZ8oj9fXa1w4Jrht94Ue2wfKtz8" target="_blank" data-ft="&amp;#123;&amp;quot;tn&amp;quot;:&amp;quot;-U&amp;quot;&amp;#125;" rel="noopener nofollow" data-lynx-mode="async"&gt;http://*******/2H3Kbr2&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Formatted in a more readable form it looks somewhat like this:</p>
  
  <pre><code>&lt;div class="_5pbx userContent _3576" data-ft="&amp;#123;&amp;quot;tn&amp;quot;:&amp;quot;K&amp;quot;&amp;#125;"&gt;
      &lt;p&gt;
          We&amp;#039;re proud to be named one of Built In NYC&amp;#039;s Best Places to Work in 
          2019, ranking in the top 10 for Best Midsize Places to Work and top 3 (!) for 
          Best Perks and Benefits. See what it took to make the list and check out our 
          profile to see some of our job openings.
          &lt;a href="VERY_LONG_URL.........." target="_blank" data-ft="&amp;#123;&amp;quot;tn&amp;quot;:&amp;quot;-U&amp;quot;&amp;#125;" rel="noopener nofollow" data-lynx-mode="async"&gt;SHORT_LINK.....&lt;/a&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This regex <a href="https://regex101.com/r/EMIrnx/1/" rel="noreferrer">seems</a> to work okay, but I don't think it is very reliable:</p>
  
  <pre><code>/&lt;div class="[^"]+ userContent [^"]+" data-ft="[^"]+"&gt;(.+?)&lt;\/div&gt;/g
  </code></pre>
  
  <p>If for example the post contained another div-element then it wouldn't work properly. In addition to that I have no way of knowing the time/date the post was created using this approach?</p>
  
  <p>Any ideas how I could relatively reliably extract the most recent 2-3 posts including the creation date/time?</p>