擅长:python、mysql、java
<p>我使用一个没有代理服务器的解决方案。为了添加executePhantomJS函数,我根据下面的链接修改了selenium源代码。</p>
<p><a href="https://github.com/SeleniumHQ/selenium/pull/2331/files" rel="nofollow noreferrer">https://github.com/SeleniumHQ/selenium/pull/2331/files</a></p>
<p>然后在获取phantomJS驱动程序后执行以下脚本:</p>
<pre><code>from selenium.webdriver import PhantomJS
driver = PhantomJS()
script = """
var page = this;
page.onResourceRequested = function (req) {
console.log('requested: ' + JSON.stringify(req, undefined, 4));
};
page.onResourceReceived = function (res) {
console.log('received: ' + JSON.stringify(res, undefined, 4));
};
"""
driver.execute_phantomjs(script)
driver.get("http://ariya.github.com/js/random/")
driver.quit()
</code></pre>
<p>然后所有请求都记录在控制台中(通常是ghostdriver.log文件)</p>