function complete(){ fs.touch(compareConfigFileName); var compareConfigFile = fs.read(compareConfigFileName); var compareConfigJSON = JSON.parse(compareConfigFile || '{}'); compareConfigJSON.compareConfig = compareConfig; fs.write(compareConfigFileName, JSON.stringify(compareConfigJSON,null,2), 'w'); console.log( 'Comparison config file updated.' //,configData ); }
logToFile : function(errorList) { this.log('\nWriting ' + (errorList.length / 6) + ' errors to log file.', true); filesystem.touch(this.logFile); var stream = filesystem.open(this.logFile, 'w'); var i = 0; for (i; i < errorList.length; i++) { stream.writeLine(errorList[i]); } stream.close(); },
function FileSave(theContent){ // var theNewContent=theContent.replace(/.+?<table id="documentsTable">/g,""); // phantom.outputEncoding="utf8"; //★★★乱码时请注意调整编码 var fs = require('fs'); var fs_diff = require('fs'); var path ='C:\\JJS_Notiecs\\JJS_Notice.txt'; var path_diff ='C:\\JJS_Notiecs\\CCB_Notice_diff.txt'; if(fs.exists(path)){ //如果存在则将文件内容进行比较。 var content_LastTime=fs.read(path); fs_diff.touch(path_diff); //先创建一个空文件。 if(theContent==content_LastTime){ fs_diff.write(path_diff,'上海黄金交易所:今日无更新','w'); }else{ fs_diff.write(path_diff,'上海黄金交易所:今日有更新注意查看','w'); } } fs.touch(path); fs.write(path,theContent,'w'); }
page.open(address, method, params, function (status) { if (status !== 'success' || (statusCode != 200 && statusCode != null)) { console.log(statusCode, 'Unable to load the address!'); if (fs.exists(output)) { fs.remove(output); } try { fs.touch(output); } catch (e) { phantom.exit(1); throw e } phantom.exit(1); } else { renderPage() } });
parseFileUpload(request, params, null, function (data, enc) { if (!data.filename) { return BufferFactory(data, enc); } // 新建存放附件缺少的目录 fs.makeTree(join(prefix, folder)); // 生成空文件 fs.touch(fullPath); data.path = filePath; return fs.open(fullPath, { write: true, binary: true }); });
page.open(input, function(status){ if (status !== 'success' || (resourceStatusCode !== null && resourceStatusCode != 200)) { console.log(resourceStatusCode, 'Failed to load the input!'); if (fs.exists(output)) { fs.remove(output); } try { fs.touch(output); } catch (e) { phantom_exit(1, e.message); } phantom_exit(1); } else { render_pdf(is_http(input) ? null : page.content); } });
var unzip = function(source, dest) { var zip = new ZIP.ZipFile(source); for (var i=0, ii=zip.entries.length; i<ii; ++i) { var entry = zip.entries[i]; var path = FS.join(dest, entry); if (zip.isDirectory(entry)) { FS.makeDirectory(path); } else { var parent = FS.directory(path); if (!FS.isDirectory(parent)) { FS.makeTree(parent); } var handle = FS.openRaw(path, {write: true}); zip.open(entry).copy(handle).close(); } if (entry.time > -1) { FS.touch(path, entry.time); } } }
page.open(url, function (status) { if (status !== 'success' || (statusCode != 200 && statusCode != null)) { if (fs.exists(output)) { fs.remove(output); } try { fs.touch(output); } catch (e) { console.log(e); } error('Unable to load the page. (HTTP ' + statusCode + ') (URL: ' + url + ')'); } else { /* Check whether the loaded page overwrites the header/footer setting, i.e. whether a PhantomJSPriting object exists. Use that then instead of our defaults above. See https://github.com/ariya/phantomjs/blob/master/examples/printheaderfooter.js#L66 */ window.setTimeout(function () { if (page.evaluate(function(){return typeof PhantomJSPrinting == "object";})) { paperSize = page.paperSize; paperSize.header.height = page.evaluate(function() { return PhantomJSPrinting.header.height; }); paperSize.header.contents = phantom.callback(function(pageNum, numPages) { return page.evaluate(function(pageNum, numPages){return PhantomJSPrinting.header.contents(pageNum, numPages);}, pageNum, numPages); }); paperSize.footer.height = page.evaluate(function() { return PhantomJSPrinting.footer.height; }); paperSize.footer.contents = phantom.callback(function(pageNum, numPages) { return page.evaluate(function(pageNum, numPages){return PhantomJSPrinting.footer.contents(pageNum, numPages);}, pageNum, numPages); }); page.paperSize = paperSize; } page.render(output); console.log('rendered to: ' + output, new Date().getTime()); phantom.exit(); }, render_time); } });
page.open(url, function(status) { if (status !== 'success') { console.error('Unable to access network'); phantom.exit(0); } else { console.error('this is an error'); var parsedURL = parseURL(url) , html_file = dir + '/' + parsedURL.file + '.html' , img_file = dir + '/' + parsedURL.file + '.png'; fs.makeDirectory(dir); fs.touch(html_file); var title = page.evaluate(function() { return document.title; }); inject_js("if (window) {" + " if (typeof window.prePhantom === 'function') {" + " window.prePhantom({" + " width: '" + viewportWidth + "px'" + " , height: '" + viewportHeight + "px'" + " });" + " }" + "}"); var content = page.evaluate(function (d) { var baseTag = document.createElement('base'); baseTag.href = d; document.getElementsByTagName('head')[0].appendChild(baseTag); var links = document.getElementsByTagName('link'); if (links) { for (var i=0; i < links.length; i++) { var href = links[i].href; href = href.replace(/file:\/\/\//, d + '/'); links[i].href = href; } } var scripts = document.getElementsByTagName('script'); if (scripts) { for (i=0; i < scripts.length; i++) { if (scripts[i].src) { var src = scripts[i].src; src = src.replace(/file:\/\/\//, d + '/'); if (src) scripts[i].src = src; } } } return document.getElementsByTagName('html')[0].outerHTML; }, parsedURL.domain); setTimeout(function() { if (fs.exists(html_file)) fs.remove(html_file); if (fs.exists(img_file)) fs.remove(img_file); fs.write(html_file, content, 'w'); if (scr) page.render(img_file, { format: "png" }); console.log(html_file); phantom.exit(html_file); }, 3000); } });
exports.setUp = function() { fs.touch(testFile); };