Browse Source

bot exception catch

master
filesite 7 months ago
parent
commit
870f41509e
  1. 8
      bot/Bilibili.mjs
  2. 10
      bot/Douyin.mjs
  3. 7
      bot/HeroBot.mjs
  4. 8
      bot/Kuaishou.mjs
  5. 8
      bot/Xigua.mjs

8
bot/Bilibili.mjs

@ -8,7 +8,6 @@ class Bilibili extends HeroBot { @@ -8,7 +8,6 @@ class Bilibili extends HeroBot {
async scrap(url) {
let data = {url: url, done: false};
try {
let options = {
userAgent: configs.userAgent,
viewport: configs.viewport
@ -18,12 +17,18 @@ class Bilibili extends HeroBot { @@ -18,12 +17,18 @@ class Bilibili extends HeroBot {
options.connectionToCore = this.heroServer;
}
try {
const profile = await this.init('bilibili');
if (profile) {
options.userProfile = profile;
}
}catch(err) {
console.error("Error got when init Bilibili bot", err);
}
const hero = new Hero(options);
try {
hero.use(ClientLogPlugin); //开启log
await hero.goto(url, configs.heroBotOptions);
@ -79,6 +84,7 @@ class Bilibili extends HeroBot { @@ -79,6 +84,7 @@ class Bilibili extends HeroBot {
data.done = true;
}catch(error) {
console.error("Error got when request %s via hero: %s", url, error);
await hero.close();
}
return data;

10
bot/Douyin.mjs

@ -8,7 +8,6 @@ class Douyin extends HeroBot { @@ -8,7 +8,6 @@ class Douyin extends HeroBot {
async scrap(url) {
let data = {url: url, done: false};
try {
let options = {
userAgent: configs.userAgent,
viewport: configs.viewport
@ -18,13 +17,18 @@ class Douyin extends HeroBot { @@ -18,13 +17,18 @@ class Douyin extends HeroBot {
options.connectionToCore = this.heroServer;
}
try {
const profile = await this.init('douyin');
data.bot = this.name;
if (profile) {
options.userProfile = profile;
}
}catch(err) {
console.error("Error got when init Douyin bot", err);
}
const hero = new Hero(options);
try {
hero.use(ClientLogPlugin); //开启log
await hero.goto(url, configs.heroBotOptions);
@ -73,9 +77,11 @@ class Douyin extends HeroBot { @@ -73,9 +77,11 @@ class Douyin extends HeroBot {
await hero.close();
data.bot = this.name;
data.done = true;
}catch(error) {
console.error("Error got when request %s via hero: %s", url, error);
await hero.close();
}
return data;

7
bot/HeroBot.mjs

@ -29,7 +29,6 @@ class HeroBot { @@ -29,7 +29,6 @@ class HeroBot {
const base_url = this.supportedBots[botName];
try {
this.name = botName;
let options = {
@ -48,8 +47,9 @@ class HeroBot { @@ -48,8 +47,9 @@ class HeroBot {
}
//console.log('Hero init配置', configs);
const hero = new Hero(options);
try {
hero.use(ClientLogPlugin); //开启log
await hero.goto(base_url, configs.heroBotOptions);
@ -65,7 +65,8 @@ class HeroBot { @@ -65,7 +65,8 @@ class HeroBot {
return latestUserProfile;
}catch(error) {
console.error("Error got when request %s via hero: %s", base_url, error);
console.error("Error got when bot init with %s via hero, error: %s", base_url, error);
await hero.close();
}
return false;

8
bot/Kuaishou.mjs

@ -8,7 +8,6 @@ class Kuaishou extends HeroBot { @@ -8,7 +8,6 @@ class Kuaishou extends HeroBot {
async scrap(url) {
let data = {url: url, done: false};
try {
let options = {
userAgent: configs.userAgent,
viewport: configs.viewport
@ -18,12 +17,18 @@ class Kuaishou extends HeroBot { @@ -18,12 +17,18 @@ class Kuaishou extends HeroBot {
options.connectionToCore = this.heroServer;
}
try {
const profile = await this.init('kuaishou');
if (profile) {
options.userProfile = profile;
}
}catch(err) {
console.error("Error got when init Kuaishou bot", err);
}
const hero = new Hero(options);
try {
hero.use(ClientLogPlugin); //开启log
await hero.goto(url, configs.heroBotOptions);
@ -60,6 +65,7 @@ class Kuaishou extends HeroBot { @@ -60,6 +65,7 @@ class Kuaishou extends HeroBot {
data.done = true;
}catch(error) {
console.error("Error got when request %s via hero: %s", url, error);
await hero.close();
};
return data;

8
bot/Xigua.mjs

@ -8,7 +8,6 @@ class Xigua extends HeroBot { @@ -8,7 +8,6 @@ class Xigua extends HeroBot {
async scrap(url) {
let data = {url: url, done: false};
try {
let options = {
userAgent: configs.userAgent,
viewport: configs.viewport
@ -18,12 +17,18 @@ class Xigua extends HeroBot { @@ -18,12 +17,18 @@ class Xigua extends HeroBot {
options.connectionToCore = this.heroServer;
}
try {
const profile = await this.init('xigua');
if (profile) {
options.userProfile = profile;
}
}catch(err) {
console.error("Error got when init Xigua bot", err);
}
const hero = new Hero(options);
try {
hero.use(ClientLogPlugin); //开启log
await hero.goto(url, configs.heroBotOptions);
@ -69,6 +74,7 @@ class Xigua extends HeroBot { @@ -69,6 +74,7 @@ class Xigua extends HeroBot {
data.done = true;
}catch(error) {
console.error("Error got when request %s via hero: %s", url, error);
await hero.close();
};
return data;

Loading…
Cancel
Save