Evaluate javascript on a local html file (without browser)

亡梦爱人 提交于 2019-11-28 13:02:48

Well, in the end I came down to the following possible solutions:

  • Run Chrome headless and collect the html output (thanks to koenp for the link!)
  • Run PhantomJS, a headless browser with a javascript api
  • Run HTMLUnit; same thing but for Java
  • Use Ghost.py, a python-based headless browser (that I haven't seen suggested anyyyywhere for some reason!)
  • Write a DOM-based javascript interpreter based on Pyv8 (Google v8 javascript engine) and add this to my current "half-solution" with mechanize.

For now, I have decided to use either use Ghost.py or my own modification of the PySide/PyQT Webkit (how ghost works) to evaluate the javascript, as apparently they can run quite fast if you optimize them to not download images and disable the GUI.

Hopefully others will find this list useful!

Well you will need something that both understands the DOM and understand Javascript, so that comes down to a headless browser of some sort. Maybe you can take a look at the selenium webdriver, but I guess you already did that. I don't hink there is an easy way of doing this without running the stuff in an actually browser engine.

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