0

I'm attempting to write a script which is able to take a screenshot given an url using phantom.js. This works great when I supply the url(s). However, I would like to be able to read urls from a file in much the same way as in: here and here. However, all methods return with

unable to open file 'filename.txt'

Am I missing something here? Working from a win7 installation.

EDIT:

var fs = require('fs');
var file_h = fs.open('urls.txt', 'r');
var line = file_h.readLine();

while(line) {
console.log(line);
line = file_h.readLine(); 
}

file_h.close();

The output I get is:

unable to open file 'urls.txt'
phantomjs://platform/fs.js:79 in open
  • Have you tried to use the whole filepath? `c:/dira/dib/.../filename.txt`? Also make sure the O.S. allow the phanton process to access the file. – lmarqs Feb 14 '19 at 13:13
  • yes full path, also with file:///C:/path/file.txt - same result – Lars Christian Jensen Feb 14 '19 at 13:26
  • please post your code with sample files included.. – Nikos M. Feb 14 '19 at 13:27
  • Possible duplicate of [How to open a local disk file with Javascript?](https://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript) – Rafael Herscovici Feb 14 '19 at 13:36
  • I do feel rather silly now. The code I posted actually do work. For some reason an extra extension had been added to my local file, which I failed to realize. So rather than urls.txt, the file was named urls.txt.txt. Thanks for your time all the same – Lars Christian Jensen Feb 15 '19 at 08:16

0 Answers0