Scraping facebook likes, comments and shares with Beautiful Soup

人走茶凉 提交于 2021-02-10 20:34:04

问题


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:

this is the code:

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?


回答1:


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.




回答2:


Probably, you can try use the Selenium.



来源:https://stackoverflow.com/questions/58689247/scraping-facebook-likes-comments-and-shares-with-beautiful-soup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!