在本地html文件上评估javascript(无浏览器) [英] Evaluate javascript on a local html file (without browser)

查看:104
本文介绍了在本地html文件上评估javascript(无浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想自动化一个Sharepoint站点,特别是将数据从数据库中提取出来,我和我的同事只能通过前端访问。



我最终设法使用Python-NTLM来实现这个功能(通过python),并通过修补其部分源代码代码来修复一个重复发生的错误。

现在,我希望我的最终障碍是:我需要提交的部分表单似乎是输出JavaScript函数:|和lo,瞧...机械化不支持JavaScript。我不想在python中模拟自己的javascript功能,因为我理想上喜欢可重复使用的解决方案......

所以,任何人都知道我可以如何评估从Sharepoint下载的本地html上的javascript?我只是想以某种方式运行javascript(完成页面的加载),但没有浏览器。



我已经看过硒,但是它很慢我需要完成的工作量......我目前正在研究PyV8来尝试并评估自己的JavaScript ...但肯定必须有一个应用程序或库(或任何),可以做到这一点??

解决方案

好,最后我回到了以下可能的解决方案:




  • 运行Chrome headless 并收集html输出(感谢链接的koenp!)

  • 运行PhantomJS ,一个带有javascript api的无头浏览器

  • 运行HTMLUnit ;同样的事情,但对于Java

  • 使用Ghost.py ,一个基于python的无头浏览器(我还没有看到anyyyywhere )

  • 编写一个基于Pyv8(Google v8 javascript engine)的基于DOM的javascript解释器,并将其添加到机械化的当前half-solution中。
  • 现在,我决定使用Ghost.py或我自己修改的PySide / PyQT Webkit(如何运行)来评估javascript,因为显然他们可以运行得非常快,如果你优化他们不下载图像和禁用GUI。



    希望其他人会发现这个列表有用!


    This is part of a project I am working on for work.

    I want to automate a Sharepoint site, specifically to pull data out of a database that I and my coworkers only have front-end access to.

    I FINALLY managed to get mechanize (in python) to accomplish this using Python-NTLM, and by patching part of it's source code to fix a reoccurring error.

    Now, I am at what I would hope is my final roadblock: Part of the form I need to submit seems to be output of a JavaScript function :| and lo and behold... Mechanize does not support javascript. I don't want to emulate the javascript functionality myself in python because I would ideally like a reusable solution...

    So, does anyone know how I could evaluate the javascript on the local html I download from sharepoint? I just want to run the javascript somehow (to complete the loading of the page), but without a browser.

    I have already looked into selenium, but it's pretty slow for the amount of work I need to get done... I am currently looking into PyV8 to try and evaluate the javascript myself... but surely there must be an app or library (or anything) that can do this??

    解决方案

    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!

    这篇关于在本地html文件上评估javascript(无浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆