jsdom

jsdom.env not working on node.js C9

只谈情不闲聊 提交于 2019-11-30 21:31:53
So I've been working with Node.js on C9 recently and ran into this problem in a javascript file: jsdom.env("", function(err, window) { TypeError: jsdom.env is not a function Here is my code: var jsdom = require('jsdom'); var $; jsdom.env("", function(err, window) { console.log("what"); if (err) { console.error(err); return; } $ = require("jquery")(window); $.ajax(settings).done(function (response) { console.log(response); }); }); I updated all my dependencies as well as Node itself but still get this problem. Does anyone know what's up? I was facing the same issue. Was looking for the solution

How do you add stylesheets to JSDOM

旧街凉风 提交于 2019-11-30 19:13:33
I am currently working on a project that requires me to have computed styles send to the browser via JSDOM. I am currently looking for a way to inject some basic CSS into JSDOM so that it could compute the correct inline style (Yes I know that's bad). From what I have found out I can use JSDOM Level 2, but from there I can't find any documentation on how to inject the styles. This is what I have so far; var document = jsdom.jsdom('<!DOCTYPE html><html><head></head><body id="abody" ></body></html>', jsdom.level(2, 'style'), { features : { FetchExternalResources : ['script', 'css'],

jsdom.env not working on node.js C9

六眼飞鱼酱① 提交于 2019-11-30 17:31:17
问题 So I've been working with Node.js on C9 recently and ran into this problem in a javascript file: jsdom.env("", function(err, window) { TypeError: jsdom.env is not a function Here is my code: var jsdom = require('jsdom'); var $; jsdom.env("", function(err, window) { console.log("what"); if (err) { console.error(err); return; } $ = require("jquery")(window); $.ajax(settings).done(function (response) { console.log(response); }); }); I updated all my dependencies as well as Node itself but still

JSDOM in nodeJS: How do I get back the manipulated html?

有些话、适合烂在心里 提交于 2019-11-30 09:00:07
I am trying to manipulate a remote HTML and return it manipulated. I decided to use JSDOM but cannot figure out how to get the manipulated HTML back. Any ideas? jsdom.env({ url: "http://www.cnn.com", scripts: ["http://code.jquery.com/jquery.js"], done: function (err, window) { var $ = window.$; console.log("HN Links"); var src = $(".ghciTopStoryImage1 img").attr('src','http://lorempixel.com/396/220/'); var headline = $(".blkbigheader span").html('header'); var description = $(".blkbigheader").parent().find("p a:eq(0)").html('text'); // not working.... content =$(window.document).html(); } });

How to prevent “Property '…' does not exist on type 'Global'” with jsdom and typescript?

廉价感情. 提交于 2019-11-30 06:17:31
问题 I try to convert an existing project to use Typescript and I have problems doing so with my testing setup. I had a setup file for my tests that sets up jsdom so that all my DOM interacting code works during my tests. Using Typescript (ts-node with mocha) I always get errors like this: Property 'window' does not exist on type 'Global'. To prevent this I tried patching the NodeJS.Global interface like this: declare namespace NodeJS{ interface Global { document: Document; window: Window;

How to prevent “Property '…' does not exist on type 'Global'” with jsdom and typescript?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 22:16:56
I try to convert an existing project to use Typescript and I have problems doing so with my testing setup. I had a setup file for my tests that sets up jsdom so that all my DOM interacting code works during my tests. Using Typescript (ts-node with mocha) I always get errors like this: Property 'window' does not exist on type 'Global'. To prevent this I tried patching the NodeJS.Global interface like this: declare namespace NodeJS{ interface Global { document: Document; window: Window; navigator: Navigator; } } But this didn't change anything. How do I enable those browser properties on the

Scrape a webpage and navigate by clicking buttons

余生长醉 提交于 2019-11-29 19:33:55
I want to perform following actions at the server side: 1) Scrape a webpage 2) Simulate a click on that page and then navigate to the new page. 3) Scrape the new page 4) Simulate some button clicks on the new page 5) Sending the data back to the client via json or something I am thinking of using it with Node.js. But am confused as to which module should i use a) Zombie b) Node.io c) Phantomjs d) JSDOM e) Anything else I have installed node,io but am not able to run it via command prompt. PS: I am working in windows 2008 server Zombie.js and Node.io run on JSDOM, hence your options are either

JSDOM in nodeJS: How do I get back the manipulated html?

点点圈 提交于 2019-11-29 13:10:30
问题 I am trying to manipulate a remote HTML and return it manipulated. I decided to use JSDOM but cannot figure out how to get the manipulated HTML back. Any ideas? jsdom.env({ url: "http://www.cnn.com", scripts: ["http://code.jquery.com/jquery.js"], done: function (err, window) { var $ = window.$; console.log("HN Links"); var src = $(".ghciTopStoryImage1 img").attr('src','http://lorempixel.com/396/220/'); var headline = $(".blkbigheader span").html('header'); var description = $(".blkbigheader")

npm install jsdom error on windows?

给你一囗甜甜゛ 提交于 2019-11-29 12:22:06
问题 I have installed nodejs on my windows pc. And it was working fine. But when I tried to install jsdom using "npm install jsdom" I was prompoted by this error. node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild info it worked if it ends with ok ERR! Error: Python does not seem to be installed at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:78:14) at Object.oncomplete (C:\Program

mocha command giving ReferenceError: window is not defined

老子叫甜甜 提交于 2019-11-29 01:45:47
问题 I am using command: mocha --compilers :./test/babel-setup.js --recursive --watch It is giving error: ReferenceError: window is not defined I have the following in my babel-setup.js: require("babel/register")({ compact: false }); I am using node 0.12.7 and "mocha": "^2.2.5" and "jsdom": "^3.1.2". I already have jsdom installed with the project. What is causing the error? 回答1: I was able to use jsdom-global to fix this issue. Follow the instructions in that link to install. Specifically, run