gpt4 book ai didi

javascript - PhantomJS 为什么返回 null?

转载 作者:行者123 更新时间:2023-11-29 22:11:13 24 4
gpt4 key购买 nike

var page = require('webpage').create();
page.open('http://www.alfeker.net/', function () {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js",
function () {
try {
var b = [];
b = page.evaluate(function () {
$("a.titr").each(function () {
return b = $(this).text();
});
});
} catch (e) {
console.log(e);
}
console.log(b);
});
});

最佳答案

var page = require('webpage').create();
var fs=require('fs');
var system = require('system');
var url = 'http://www.google.com/';
page.open(url, function(status) {
var links = page.evaluate(function() {
return [].map.call(document.querySelectorAll('a.gbzt'), function(link) {
return link.getAttribute('href');
});
});
var _urls = links.join('\n');
try
{
fs.write('/home/JIM/Documents/phantomjs-1.9.1-linux-x86_64/bin/MEFile/Log.txt', _urls , 'w');
}
catch (e)
{
console.log(e);
}
if (system.args.length < 2) {
console.log("Usage: readFile.js FILE");
phantom.exit(1);
}
var content = '',
f = null,
lines = null,
eol = system.os.name == 'windows' ? "\r\n" : "\n";
try {
f = fs.open(system.args[1], "r");
content = f.read();
} catch (e) {
console.log(e);
}
if (f) {
f.close();
}
if (content) {
lines = content.split(eol);
for (var i = 0, len = lines.length; i < len; i++) {
console.log(lines[i]);
}
}
phantom.exit();
});

关于javascript - PhantomJS 为什么返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17924478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com