JSDOM scraping on cloudfoundry doesn't work

青春壹個敷衍的年華 提交于 2019-12-24 12:49:27

问题


I'm using the jsdom node.js module for an app that does some web scraping to get some data it needs. This works perfectly fine when I run locally.

When I push the application to cloudfoundry however, it crashes. The log is as follows:

====> /logs/stderr.log <====

/var/vcap/data/dea/apps/caretogethersandbox-0-8b20af9255bbf552d0f490cb60d0df55/app/node_modules/jsdom/lib/jsdom.js:171 features = JSON.parse(JSON.stringify(window.document.implementation._fea ^TypeError: Cannot read property 'implementation' of undefined

Is there something I'm missing here? I'm pretty stumped. I know the code I've written works fine, it just seems to be an issue between the module and cloudfoundry.


回答1:


I was able to reproduce this problem pretty easily. It seems jsdom relies on a native compiled library called Contextify (https://github.com/brianmcd/contextify) and also has some bindings to Python from what I can gather. These are not supported by Cloud Foundry at present. There is a similar question on Github about this problem;

https://github.com/tmpvar/jsdom/issues/436

The last post at the time of writing this suggests the use of two 100% JS libraries called Domino and Zepto Node, they may well be worth checking out.




回答2:


With only what you posted to go by its pretty much impossible to give you a direct answer.

But I have a couple of suggestions.

  1. You have environmental variables that don't work the same in production as they do in development.

  2. jsdom relies on jquery that is normally loaded-in externally. Perhaps jquery is not loading properly.

Have you heard of cheerio. Its an alternative to jsdom that implements a subset of jquery and does not need to load jquery in externally. This makes much faster than jsdom.

You can watch this video created by the author for introduction to cheerio and learn more of its benefits.

Use the sample code on the cheerio github page and upload it your cloudfoundry account to see if everything works. Then you can make decision on weather to switch to cheerio.



来源:https://stackoverflow.com/questions/12083190/jsdom-scraping-on-cloudfoundry-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!