我通过Python使用Selenium和PhantomJS。
我遇到的问题是,我正在随机获取黑色屏幕截图。例如,此页面呈现黑色的400x300 png文件:
http://ib.adnxs.com/cr?id=17708944
使用以下代码:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36")
driver = webdriver.PhantomJS(executable_path="C:\Python27\Lib\phantomjs.exe",
desired_capabilities=dcap)
driver.get('http://ib.adnxs.com/cr?id=17708944')
driver.save_screenshot('foo.png')
有什么想法吗?