【发布时间】:2015-09-22 22:02:59
【问题描述】:
我读过类似的问题,一个应该是答案,但是当我尝试它时,它只给出了部分解决方案。 我参考这个问题:Disable images in Selenium Python
我的问题是我尝试了解决方案,有些图像没有出现,但图像来自:
<img href="www.xxx.png">
正在加载。 有没有办法告诉 firefox/selenium 不要得到它? 如果没有,有没有办法从我返回的 dom 元素中丢弃它,通过:
self._browser.get(url)
content=self._browser.page_source
例如通过在 dom 树上进行某种查找替换? 浏览器配置和上一个问题的浏览器一样:
firefox_profile = webdriver.FirefoxProfile()
# Disable CSS
firefox_profile.set_preference('permissions.default.stylesheet', 2)
# Disable images
firefox_profile.set_preference('permissions.default.image', 2)
# Disable Flash
firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
# Set the modified profile while creating the browser object
self._browser = webdriver.Firefox(firefox_profile=firefox_profile)
更新:
我继续挖掘,我学到的是,如果我检查 selenium/firefox 组合的文本文档,我看到了,它没有带来图像并将它们保留为链接。 但是当我这样做时:
self._browser.save_screenshot("info.png")
我有一个 24 兆的文件,其中加载了所有 img 链接。
谁能给我解释一下这个问题?
谢谢!
【问题讨论】:
标签: python firefox selenium selenium-webdriver