Non-browser emulation of JavaScript - is it possible?

前端 未结 8 2297
眼角桃花
眼角桃花 2020-12-17 21:13

I have a new project I am working on that involves fetching a webpage, (using PHP and cURL) parsing the HTML and javascript out of it and then handling the data in the resul

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 22:00

    You'll have to go one step further than Rhino if you want to execute real live web pages, because the JavaScript on those pages will expect to be able to use objects that are native to a browser environment. A server-side JavaScript engine like Rhino won't have those objects.

    John Resig (creator of jQuery) started a project called Env.js a couple of years ago; it might be what you're looking, for but I suspect you'll have a tough time getting consistent results from a wide variety of web pages. Here's his initial blog post about it:

    http://ejohn.org/blog/bringing-the-browser-to-the-server/

    Some similar projects are named in that post's comments.

提交回复
热议问题