Skip to content

Instantly share code, notes, and snippets.

@chiaoyaaaaa
Created September 12, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiaoyaaaaa/94dd9cef51d836c0c6a68c0bdec9b5b7 to your computer and use it in GitHub Desktop.
Save chiaoyaaaaa/94dd9cef51d836c0c6a68c0bdec9b5b7 to your computer and use it in GitHub Desktop.
catch fb first post's number of comments
from bs4 import BeautifulSoup
# 前面解釋過的,抓取所有貼文
soup = Soup(driver.page_source, "lxml")
frames = soup.find_all(class_='du4w35lb k4urcfbm l9j0dhe7 sjgh65i0')
# 抓取第一篇的留言數
# find()裡面要先放'span'標籤再放class name
# frames[0]為第一篇貼文
# .text為抓取文字內容
# class name可能會修改,需要定期偵錯!
read = frames[0].find('span',class_="oi732d6d ik7dh3pa d2edcug0 hpfvmrgz qv66sw1b c1et5uql a8c37x1j muag1w35 enqfppq2 jq4qci2q a3bd9o3v knj5qynh m9osqain").text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment