本文介绍了用Beautiful Soup刮掉Facebook的喜欢,评论和分享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用Beautiful soup和Python刮下许多喜欢,评论和分享的内容.我已经写了一个代码,但是它返回了我的空列表,我不知道为什么:

I want to scrape number of likes, comments and shares with Beautiful soup and Python.I have wrote a code, but it returns me the empty list, I do not know why:

这是代码:

from bs4 import BeautifulSoup
import requests


website = "https://www.facebook.com/nike"

soup = requests.get(website).text
my_html = BeautifulSoup(soup, 'lxml')


list_of_likes = my_html.find_all('span', class_='_81hb')
print(list_of_likes)

for i in list_of_likes:
    print(i)

评论和喜欢也是如此.我该怎么办?

The same is with comments and likes. What should I do?

推荐答案

Facebook使用客户端呈现...这意味着在获取的HTML文档中,并将其存储在 soup 变量中是仅当您在浏览器中显示内容时才真正呈现内容的javascript代码.

Facebook uses client side rendering...that means in the HTML document that you get and you have it stored in soup variable is just javascript code that actually renders the content only when you display it in browser.

这篇关于用Beautiful Soup刮掉Facebook的喜欢,评论和分享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 05:34