This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 建立一個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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup as Soup | |
# class name可能會修改,需要定期偵錯! | |
soup = Soup(driver.page_source, "lxml") | |
frames = soup.find_all(class_='du4w35lb k4urcfbm l9j0dhe7 sjgh65i0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
NewerOlder