Skip to content

Instantly share code, notes, and snippets.

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