Skip to content

Commit

Permalink
ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Miniast committed May 8, 2024
1 parent 0cf8d3d commit bb4b93b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Crawler extends EventEmitter {
retries: 3,
retryInterval: 2000,
timeout: 15000,
isJson: true,
isJson: false,
};
this.options = { ...defaultOptions, ...options };

Expand Down Expand Up @@ -148,7 +148,7 @@ class Crawler extends EventEmitter {
try {
options.preRequest!(options, async (err?: Error | null) => {
if (err) {
log.error(err);
log.debug(err);
return this._handler(err, options);
}
return await request();
Expand Down Expand Up @@ -222,7 +222,7 @@ class Crawler extends EventEmitter {
try {
response.$ = load(response.body);
} catch (err) {
log.error(err);
log.warn("HTML detected failed. Set jQuery to false to mute this warning.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const alignOptions = (options: any): any => {
gotOptions.headers.referer = options.referer;
}
else {
const domain = options.url.match(/^(\w+):\/\/([^\/]+)/);
const domain = gotOptions.url.match(/^(\w+):\/\/([^\/]+)/);
if (domain) gotOptions.headers.referer = domain[0];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type requestOptions = {
forceUTF8?: boolean;
/**
* crawlerOption
* @default false
* @default true
* @description If true, the crawler will use the cheerio library to parse the HTML content.
* @see cheerio.load()
* @example If inject successfully, the response object will have "$" property, which is a function to use jQuery.
Expand Down Expand Up @@ -123,7 +123,7 @@ type requestOptions = {

/**
* @description If true, the crawler will parse the response body as JSON.
* @default true
* @default false
*/
isJson?: boolean;

Expand Down
3 changes: 0 additions & 3 deletions tests/callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ describe('Callback test', function() {
retryInterval:0,
retries:0,
timeout:100,
logger: {
log:() => {}
},
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/encoding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Crawler from '../dist/index.js';
import { expect } from 'chai';
import nock from 'nock';
import fs from 'fs';
var __dirname = "./";
var __dirname = "./tests";

describe('Encoding', function () {
before(function () {
Expand Down
6 changes: 3 additions & 3 deletions tests/requests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Request tests', function () {
beforeEach(function () {
crawler = new Crawler({
retries: 0,
json: true,
isJson: true,
jQuery: false,
});

Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Request tests', function () {
crawler = new Crawler({
headers: { 'User-Agent': 'test/1.2' },
jQuery: false,
json: true,
isJson: true,
callback: function (error, res, done) {
expect(error).to.be.null;
expect(res.body['user-agent']).to.equal('foo/bar');
Expand All @@ -113,7 +113,7 @@ describe('Request tests', function () {
'user-agent': 'test/1.2'
},
jQuery: false,
json: true,
isJson: true,
callback: function (error, res, done) {
expect(error).to.be.null;
expect(res.body['user-agent']).to.equal('foo/bar');
Expand Down

0 comments on commit bb4b93b

Please sign in to comment.