phantomjs

How to set timeout for PhantomJS?

*爱你&永不变心* 提交于 2019-12-05 15:50:31
Here's the code I have for setting it: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.resourceTimeout"] = ("5000") driver = webdriver.PhantomJS(desired_capabilities=dcap) However in my super long script, it doesn't seem to timeout when my internet is slow and a page takes longer than 5 seconds to load. There is so little documentation on PhantomJS time outs, and even less of it is for Python, so I figure maybe this isn't even the way to do it. Has anyone

Phantomjs append to file with fs.write

这一生的挚爱 提交于 2019-12-05 14:53:12
问题 How can I append to a file using fs.write() ? Using fs.write on the same files overwrites the content: var fs = require('fs'); try { fs.write("file.txt", "Hello World", 'w'); fs.write("file.txt", "Hello World", 'w'); } catch(e) { console.log(e); } 回答1: Use append mode a instead of [over]write mode w in the fs.write call. var fs = require('fs'); try { fs.write("file.txt", "Hello World", 'a'); fs.write("file.txt", "Hello World", 'a'); } catch(e) { console.log(e); } I inferred this based on the

Node js 相关知识总结

本秂侑毒 提交于 2019-12-05 14:43:32
参考教程: https://github.com/alsotang/node-lessons/blob/master/lesson4/app.js 一. 利用cheerio实现网络爬虫 示例代码: //利用cheerio实现网络爬虫 var express = require ( 'express' ); //一个 Node.js 版的 jquery,用来从网页中以 css selector 取数据,使用方式跟 jquery 一样一样的 var cheerio = require ( 'cheerio' ); // http 方面的库,可以发起 get 或 post 请求 var superagent = require ( 'superagent' ); var app = express(); app.get( '/' , function (req,res,next) { superagent.get( 'https://cnodejs.org/' ) .end( function (err,sres) { if (err){ return next(err); } // sres.text 里面存储着网页的 html 内容,将它传给 cheerio.load 之后 // 就可以得到一个实现了 jquery 接口的变量,我们习惯性地将它命名为 `$` // 剩下就都是

Running a RequireJS/WireJS app using PhantomJS

喜夏-厌秋 提交于 2019-12-05 14:26:24
I'm trying to execute a basic app that uses RequireJS (2.1.8), WireJS (0.10.2) and PhantomJS (1.9.2): When running the app using PhantomJS (this is my goal), WireJS fails to load (see error below). When running the app using Chrome, it completes properly. Please help to point out the missing part for WireJS to run properly under PhantomJS. Following are my app files. 1) app.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>SaphirJS.core</title> <script data-main="app" src="../../../target/deps/require-0.0.1/2.1.8/require.js"> </script> </head> <body> </body> </html> 2)

phantomjs 的安装

混江龙づ霸主 提交于 2019-12-05 14:09:29
PhantomJS 是一个基于Webkit的“无界面”(headless)浏览器,它会把网站加载到内存并执行页面上的 JavaScript,因为不会展示图形界面,所以运行起来比完整的浏览器要高效。 如果我们把 Selenium 和 PhantomJS 结合在一起,就可以运行一个非常强大的网络爬虫了,这个爬虫可以处理 JavaScrip、Cookie、headers,以及任何我们真实用户需要做的事情。 注意:PhantomJS 只能从它的官方网站 http://phantomjs.org/download.html) 下载。 因为 PhantomJS 是一个功能完善(虽然无界面)的浏览器而非一个 Python 库,所以它不需要像 Python 的其他库一样安装,但我们可以通过Selenium调用PhantomJS来直接使用。 PhantomJS 官方参考文档: http://phantomjs.org/documentation ubuntu16.04 下载: http://phantomjs.org/download.html 解压 1)vim /etc/profile 2)在文件的最后一行,添加安装路径path语句:(注意路径是phantomjs的安装路径) export PATH=${PATH}:/usr/local/src/phantomjs/bin/ 3)保存修改后的文件

How to fix NoClassDefFoundError: CircularOutputStream error?

落爺英雄遲暮 提交于 2019-12-05 13:40:34
I was just creating a simple maven project for Selenium WebDriver(a.k.a. Selenium 2) automated test for headless testing. I added the PhantomJS driver dependency as follows with other dependencies in pom.xml: <dependency> <groupId>com.github.detro</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.2.0</version> </dependency> But it is getting error: java.lang.NoClassDefFoundError: org/openqa/selenium/io/CircularOutputStream at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60) at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56) at org

How to handle/accept JS Alerts in PhantomJS using WebDriver?

丶灬走出姿态 提交于 2019-12-05 12:48:37
Being new to PhantomJSDriver for Selenium, how does it handle JS alerts? I've found the JSPhantom onAlert documentation, but what would the equivalent PhantomJSDriver code for Driver.SwitchTo().Alert().Accept(); be? At the moment, I've returning early with a guard clause for PhantomJSDriver , to stop exceptions, but how should js alerts in PhantomJS be interacted with? I had similar problems with PhantomJS Web Driver handling alerts. The below code seems to resolve the issue. This is a C# implementation but should work with Java too.. public IAlert GetSeleniumAlert() { //Don't handle Alerts

Is PhantomJS CPU (core) bound?

谁说我不能喝 提交于 2019-12-05 12:40:24
I'm starting to do some parallel browser based testing and want to see how many browsers I can run in parallel on an EC2 large box before hitting 100% CPU. I'm using the JMeter webdriver plugin to actually run the browsers. With FireFox it's literally 1 browser per CPU core. 4 browsers on a 4 core box is about 80% CPU. With 5 browsers it's 95% (which isn't good for performance testing). Before I go down the path of PhatomJS, are there any benchmarks that compare PhantomJS to FireFox (or even Chrome) in terms of CPU usage when running in parallel? Any idea how many PhantomJS instances I'll be

How to use phantomJS to simulate mouse hover on a HTML element

空扰寡人 提交于 2019-12-05 12:04:43
I have the phantomJS code below to fetch the HTML code: var page = require('webpage').create(); var url = 'http://example.com/'; page.open(url, function (status) { var js = page.evaluate(function () { return document; }); console.log(js.all[0].outerHTML); phantom.exit(); }); The content I want to fetch will only be read while the mouse is hover on the specific element which is controlled by JavaScript, so the code above is not working. I want to know how to simulate the mouse hover on a HTML element using the phantomJS code. Let's say I want to mouse hover over on a element then dump the HTML

Executing Javascript on Selenium/PhantomJS

亡梦爱人 提交于 2019-12-05 11:39:35
I'm using PhantomJS via Selenium Webdriver in Python and I'm trying to execute a piece of JavaScript on the page in hopes of returning a piece of data: from selenium import webdriver driver = webdriver.PhantomJS("phantomjs.cmd") # or add to your PATH driver.set_window_size(1024, 768) # optional driver.get('http://google.com') # EXAMPLE, not actual URL driver.save_screenshot('screen.png') # save a screenshot to disk jsres = driver.execute('$("#list").DataTable().data()') print(jsres) However when run, it reports KeyError . I was unable to find much documentation on the commands available, so I