Skip to content

Instantly share code, notes, and snippets.

View chiaoyaaaaa's full-sized avatar

chiaoyaaaaa chiaoyaaaaa

View GitHub Profile
@chiaoyaaaaa
chiaoyaaaaa / fb_pages_scroll.py
Created September 12, 2020 04:46
Use Javascript to scroll pages
# 建立一個scroll function
# scrolltimes代表頁面滾動的次數
def scroll(scrolltimes):
for i in range(scrolltimes):
# 每一次頁面滾動都是滑到網站最下方
js = 'window.scrollTo(0, document.body.scrollHeight);'
driver.execute_script(js)
time.sleep(2)
@chiaoyaaaaa
chiaoyaaaaa / article.py
Last active September 12, 2020 13:42
Get all articles in facebook's fan page
from bs4 import BeautifulSoup as Soup
# class name可能會修改,需要定期偵錯!
soup = Soup(driver.page_source, "lxml")
frames = soup.find_all(class_='du4w35lb k4urcfbm l9j0dhe7 sjgh65i0')
@chiaoyaaaaa
chiaoyaaaaa / like_number.py
Last active August 28, 2020 12:03
Get Facebook's numbers of like
from selenium import webdriver
from bs4 import BeautifulSoup as Soup
import pandas as pd
driver = webdriver.Chrome()
spec_url = 'https://www.facebook.com/bbcnews'
driver.get(spec_url)
soup = Soup(driver.page_source, "lxml")
frames = soup.find_all(class_='du4w35lb k4urcfbm l9j0dhe7 sjgh65i0')