gpt4 book ai didi

javascript - x-ray-phantom认证,无法有效登录

转载 作者:可可西里 更新时间:2023-11-01 02:26:04 25 4
gpt4 key购买 nike

我真的找不到任何使用 x 射线和 .driver(phantom()) 进行身份验证的示例。我已经浏览了 x 射线和 x 射线模型的文档,但找不到任何帮助。

最佳答案

/**
* Module Dependencies
*/

var Crawler = require('x-ray-crawler');
var cheerio = require('cheerio');
var join = require('path').join;
var assert = require('assert');
var phantom = require('../');
var fs = require('fs');

/**
* Tests
*/

describe('phantom driver', function() {

it('should have sensible defaults', function(done) {
var crawler = Crawler()
.driver(phantom())

crawler('http://google.com', function(err, ctx) {
if (err) return done(err);
var $ = cheerio.load(ctx.body);
var title = $('title').text();
assert.equal('Google', title);
done();
})
});

it('should work with client-side pages', function(done) {
var crawler = Crawler()
.driver(phantom());

crawler('https://exchange.coinbase.com/trade', function(err, ctx) {
if (err) return done(err);
var $ = cheerio.load(ctx.body);
var price = $('.market-num').text();
assert.equal(false, isNaN(+price));
done();
})
})

it('should support custom functions', function(done) {
var crawler = Crawler()
.driver(phantom(runner));

crawler('http://mat.io', function(err, ctx) {
if (err) return done(err);
var $ = cheerio.load(ctx.body);
var title = $('title').text();
assert.equal('Lapwing Labs', title);
done();
})

function runner(ctx, nightmare) {
return nightmare
.goto(ctx.url)
.click('.Header-logo-item+ .Header-list-item a')
.wait()
}
})
})

/**
* Read
*/

function get(path) {
return require(join(__dirname, 'fixtures', path));
}

如果有帮助,请引用下面的 github 链接。

  1. https://github.com/lapwinglabs/x-ray-phantom
  2. https://github.com/lapwinglabs/x-ray/issues/22

关于javascript - x-ray-phantom认证,无法有效登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289143/

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