3

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??

araisbec
  • 1,223
  • 3
  • 16
  • 27
  • What does the js do, make ajax calls? If so just make them yourself. – pguardiario May 04 '13 at 22:28
  • I actually posted in my answer that I would like to avoid emulating functionality as much as possible, so that I can resuse my end product on different websites. – araisbec May 05 '13 at 13:18

2 Answers2

4

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!

araisbec
  • 1,223
  • 3
  • 16
  • 27
  • Were you able to achieve it without a browser/headless browser? If yes are you allowed to share the code? – cstayyab Jul 13 '22 at 15:46
  • I was way off base with this question, but I have much better understanding of these types of tasks now. I would 100% go with Selenium WebDriver - running headless. I use Edge or Chrome. I don't have code to demonstrate, but you can Google this - it's really not too hard to pull off. ALWAYS use a headless browser when JavaScript-rendering is involved. – araisbec Jan 06 '23 at 21:48
0

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.

Koen Peters
  • 12,798
  • 6
  • 36
  • 59
  • I'm looking at phantomJS... it looks like it *could* be what I need. Would it be possible to load webpages through IE or Chrome's browser engines without *actually* opening the browser? Perhaps through a COM interface or something? – araisbec May 04 '13 at 14:43
  • 1
    I'm not sure, maybe this helps http://stackoverflow.com/questions/9210765/any-way-to-start-google-chrome-in-headless-mode – Koen Peters May 04 '13 at 14:49
  • Thanks for that link. If this was a personal project, I would definitely go that route... but since I want to make this a deploy-able solution to other IT, I would like to avoid making Google Chrome a mandatory component of the solution. – araisbec May 05 '13 at 13:21