I try to parse facebook posts which are made to a specific topic (like a company or a product). As an example posts from here https://www.facebook.com/search/latest/?q=facebook
I can login to facebook (with python) correctly and I am also able to get the source code of the page which contains the posts I am looking for. After some manual code review I found out that I wanted to get following:
<div class="_5pbx userContent" data-ft="{"tn":"K"}">
<p>Here is the text of the post I need
</p>
</div>
So I started with beautifulsoup and following code:
soup = BeautifulSoup(pageSourceCode.content, 'html.parser')
for msg in soup.find_all('div'):
print (msg.get('class')
As result I get only this ...
[u'hidden_elem']
Does someone have experience in scraping facebook posts? I only need this for myself and education purposes
Following code should work
soup = BeautifulSoup(pageSourceCode.content, 'html.parser')
divs = soup.find_all('div', class_="_5pbx userContent")
for div in divs:
p = div.find('p')
print(p.get_text())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With