使用Selenium或其他动态爬取库来模拟浏览器行为加载页面。然后将页面源代码传递给Beautiful Soup进行解析。
以下是使用Selenium和Beautiful Soup爬取动态网站的示例代码:
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get('http://dynamic-website.com')
# 等待页面加载完成
driver.implicitly_wait(5)
# 获取页面源代码
html = driver.page_source
# 使用Beautiful Soup解析页面
soup = BeautifulSoup(html, 'html.parser')