火狐驱动程序禁止加载CSS、图片、JavaScript代码,并设置无头模式:
from selenium import webdriver


fp = webdriver.FirefoxProfile()
# 限制CSS加载
fp.set_preference("permissions.default.stylesheet", 2)
# 限制图片加载
fp.set_preference('permissions.default.image', 2)
# 限制JavaScript执行
fp.set_preference('javascript.enabled', False)

options = webdriver.FirefoxOptions()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options, firefox_profile=fp)
url = 'https://www.e1yu.com/'
driver.get(url)
time.sleep(3)
cookie = driver.get_cookies()
driver.quit()

发表评论

后才能评论