小编Bor*_*ris的帖子

NodeJS,fs.readFileSync逐字符串读取和操作.怎么样?

抱歉这么愚蠢的问题,

我怎样才能在NodeJS中通过字符串从文件字符串中读取一些值,例如 - url,并最终对每个字符串进行操作?

var contents = fs.readFileSync('test.txt', 'utf8');
Run Code Online (Sandbox Code Playgroud)

什么呢?

它需要browserstack + selenium测试.我想从文件中逐个运行一些链接并对它们做一些事情.

更改了以下代码:来自

console.log(lines[i++])
Run Code Online (Sandbox Code Playgroud)

line = (lines[i++])
driver.get(line);
driver.getCurrentUrl()
                .then(function(currentUrl) {
                   console.log(currentUrl);
Run Code Online (Sandbox Code Playgroud)

但它工作一次.

var str=fs.readFileSync('test.txt');
str.split(/\n/).forEach(function(line){})


C:\nodejstest>node test1.js
C:\nodejstest\test1.js:57
str.split(/\n/).forEach(function(line){
    ^

TypeError: str.split is not a function
    at Object.<anonymous> (C:\nodejstest\test1.js:57:5)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:142:18)
    at node.js:939:3
Run Code Online (Sandbox Code Playgroud)

作品!太多了!

selenium node.js browserstack

5
推荐指数
1
解决办法
4500
查看次数

标签 统计

browserstack ×1

node.js ×1

selenium ×1