I have a set of html documents on local disk to process. I need to load each document file as document object and run a piece of javascript code over it and store the result in a separate file. I would prefer to this from python though I'm open to any other suggestions too. I tried to do this through extensions in chrome and firefox but the browsers do not allow javascript to access files on disk. Is there a solution for this?
I tried python-spidermonkey but it allows only javascript execution. I doesn't seem to be able to load the html file as docu开发者_如何转开发ment object.
What I would do is run a local web-server. Then you can send data to the server (with JavaScript, Ajax) to save to disk whatever you need.
To load the HTML file you can also usa Ajax. You could simply use .innerHTML
to load the HTML string into the Document.
If you are on a Windows pc you also have the option of doing it in an .hta file. You can use vbscript to access the local files system. They syntax is very simple and you can use DevGuru to get all your reference. I use vbscript to create Photoshop scripts and it works fine. I am sure it can do what you need as well.
I got it working with pyqt and webkit
You can't read or write files using JavaScript in a browser environment. You should try using server-side javascript.
精彩评论