嗨,大家好,我正在使用phantomjs
來進行自動化測試。這裏是我的代碼:拒絕評估字符串爲JavaScript,因爲'unsafe-eval'
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")
proxies = ['--ignore-ssl-errors=true', '--web-security=false', '--ssl-protocol=any']
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities , :args => proxies
browser = Watir::Browser.new driver
begin
browser.goto(url)
browser.goto url
browser.driver.execute_script("window.scrollBy(0,document.body.scrollHeight/2)")
sleep 1
browser.driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
sleep 1
response = browser.html
fileHtml = File.new("response_linkedin.html", "wb+")
fileHtml.puts(response)
fileHtml.close
browser.close
response
rescue Exception => e
raise e.message.to_s
ensure
browser.close
end
問題是,當我試圖執行腳本window.scrollBy(0,document.body.scrollHeight/2)
滾動窗口,我的代碼返回錯誤象下面這樣:
「的errorMessage」:「拒絕評價一個字符串作爲JavaScript的,因爲「不安全-EVAL」不是腳本在下面的內容安全策略指令
我想知道我爲什麼不能內部phantomjs
運行腳本註釋所允許源的:我使用phantomjs
版本2.2.1,對於一些人建議我降級版本1.9.8(source),不幸的是降級到版本1.9.8似乎不起作用。任何人都可以幫助我?
感謝你好,我想知道如果用'無頭chrome',我怎麼能欺騙與虛假用戶代理的瀏覽器? –
'options:{emu lation:{userAgent:'foo; bar'}' - https://github.com/watir/watir/blob/master/spec/browser_spec.rb#L83 – titusfortner
謝謝隊友你的建議可以幫助我很多 –