这是我的代码:
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.9; rv:25.0) Gecko/20100101 Firefox/25.0 "
)
driver = webdriver.PhantomJS(desired_capabilities=dcap)
driver.get("http://pujiankang.cn/index0.html")
jscode = '''
var webPage = require('webpage');
var page = webPage.create();
var settings = {
headers: {
"Referer": "http://www.google.com"
}
};
page.onLoadStarted = function() {
page.customHeaders = {};
};
page.open('http://pujiankang.cn/index0.html', settings, function(status) {
});
'''
driver.execute_script(jscode)
driver.save_screenshot('test.png')
driver.quit
运行时会出现错误:
errorMessage":"Can't find variable: require","request"...
但是我直接用phantomjs运行这个js文件,这很有效!
命令:phantomjs referer.js
如何解决此问题?