admin 管理员组文章数量: 1086019
I want to disable JavaScript while scraping using scrapy and selenium. Moto of doing that is to increase scraping speed. I found the preference for Firefox driver but not PhantomJS.
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
driver = webdriver.Firefox(firefox_profile=firefox_profile)
driver.get('/')
How can this be done for PhantomJS webdriver?
I want to disable JavaScript while scraping using scrapy and selenium. Moto of doing that is to increase scraping speed. I found the preference for Firefox driver but not PhantomJS.
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
driver = webdriver.Firefox(firefox_profile=firefox_profile)
driver.get('http://www.quora./')
How can this be done for PhantomJS webdriver?
Share Improve this question edited Aug 20, 2015 at 10:31 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked Aug 20, 2015 at 10:23 amanaman 1,9954 gold badges20 silver badges29 bronze badges 02 Answers
Reset to default 8The WebDriver protocol in PhantomJS is a pure JavaScript implementation that is known as Ghostdriver. It makes heavy use of page.evaluate()
to access the DOM and there is really no other way to access the DOM, interact with the page or do anything meaningful with PhantomJS. You shouldn't do this.
If you still want to go through with it, this should work:
cap = webdriver.DesiredCapabilities.PHANTOMJS
cap["phantomjs.page.settings.javascriptEnabled"] = False
driver = webdriver.PhantomJS(desired_capabilities=cap)
If the site does not require JavaScript, just use scrapy alone. There is no need for selenium. Scrapy is extremely fast for non JavaScript pages.
本文标签: pythonHow to disable JavaScript in PhantomJS through Selenium WebDriverStack Overflow
版权声明:本文标题:python - How to disable JavaScript in PhantomJS through Selenium WebDriver - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744073372a2528899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论