如何使用 BS4 或其他库从网站页面上的 "View source" 获取代码?

How can I get the code from the "View source" on the site page using BS4 or another library?

当我们浏览网站时,我们可以选择“查看源代码”和“查看页面源代码”。 BS4使得从“查看页面源码”获取数据成为可能,“查看源码”是否可以获取数据?如果没有,有没有其他方法可以得到它们?非常感谢您的帮助!

解法:

from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get("my_URL")

time.sleep(10)

html_source = driver.page_source

使用 headless 选项我们启动浏览器而不显示 window。整个javascript的执行需要暂停,否则我们需要的数据来不及加载。结果,我们得到的数据与“查看源代码”中的数据相匹配。