gpt4 book ai didi

python - 用 beautifulsoup/python 解析公共(public) facebook 帖子

转载 作者:行者123 更新时间:2023-11-28 17:23:21 24 4
gpt4 key购买 nike

我尝试解析针对特定主题(如公司或产品)的 Facebook 帖子。作为示例,来自此处的帖子 https://www.facebook.com/search/latest/?q=facebook

我可以正确登录到 facebook(使用 python),我还可以获得包含我要查找的帖子的页面的源代码。经过一些手动代码审查后,我发现我想要获得以下信息:

<div class="_5pbx userContent" data-ft="&#123;&quot;tn&quot;:&quot;K&quot;&#125;">
<p>Here is the text of the post I need
</p>
</div>

所以我开始使用 beautifulsoup 和以下代码:

soup = BeautifulSoup(pageSourceCode.content, 'html.parser')

for msg in soup.find_all('div'):
print (msg.get('class')

结果我只得到这个...

[u'hidden_elem']

有人有抓取 Facebook 帖子的经验吗?我只需要这个用于我自己和教育目的

最佳答案

下面的代码应该可以工作

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())

关于python - 用 beautifulsoup/python 解析公共(public) facebook 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40441335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com