By popular request here’s an experimental setup for running WebKit from TD.
Via this method you can fully interact with websites through Python (including support for DOM handling, CSS selectors, JSON, Canvas, and SVG), and capture output screenshots.
In the example below I load the Google Images website in a headless Webkit browser, enter my searchterm, click the search button, and save a screencapture to a PNG. If you scroll the screenshot below to the right you’ll see the result.
HOWTO:
- first read this how to import a python module
- after that, install the selenium python package.
- download latest PhantomJS for windows
- add path to location of phantomjs to your windows PATH environment variable
- done
(The first time you run the script below, windows firewall will start moaning about PhantomJS, so you’ll have to give it permission.)
First we check if it works without TD, by entering these 5 commands in windows cmd.exe:
[code]$ python
from selenium import webdriver
browser = webdriver.PhantomJS(‘phantomjs’)
browser.get(“http://www.google.com”)
browser.title
[/code]
if the answer is'Google'
everything is working
-
in TD, somehow the selenium package wasn’t visible by default, so I added the path in Touchdesigner under Edit ->Preferences in the field labelled “Python 32/64 bit Module Path”.
The path I added is: C:/Python33/Lib/site-packages/selenium-2.45.0-py3.3.egg -
run attached toefile, and change the folder where it saves/reads the PNG (*)
headless_webkit.toe (4.05 KB)
=====================================================================
Extra options
You can set the browser window size and user agent, so you can load the mobile or desktop variant of a website. The following example loads the BBC website as a Chrome desktop browser in 1600x1050 and also as a iPhone 1 in 320x480, and renders both pages to a PNG(*).
headless_webkit_useragent_windowsize_v2.toe (4.21 KB)
have fun!
-idzard
(*)feature request: Derivative, it would be cool if someday the moviefileinTOP Class could read png images encoded as base64 strings, that way we wouldn’t have to save to disk first to read WebKit screencaptures in TD.