Skip to content

Commit

Permalink
v2.1.5 (#41)
Browse files Browse the repository at this point in the history
fix: 秒杀场景`url`为空容错
update: 新镜像地址
  • Loading branch information
meooxx authored Mar 21, 2022
1 parent 2aa8faf commit 288501e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
registry=https://registry.npm.taobao.org/
PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors
registry=https://registry.npmmirror.com/
PUPPETEER_DOWNLOAD_HOST=https://npmmirror.com/mirrors
3 changes: 2 additions & 1 deletion puppeteerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const getBrowser = async () => {
args: [
'--no-sandbox',
'–disable-gpu', // GPU硬件加速
'–no-first-run' // 没有设置首页。在启动的时候,就会打开一个空白页面。
'–no-first-run', // 没有设置首页。在启动的时候,就会打开一个空白页面。
'--disable-blink-features=AutomationControlled'
]
};
if (isDebug) {
Expand Down
12 changes: 11 additions & 1 deletion tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ class Tools {
`https://itemko.jd.com/itemShowBtn?skuId=${skuId}&callback=fn131231`
);
const url = this.parseJsonp(await r.text()).url;
if (!url) {
console.log('未进入到秒杀结算页面');
break;
}
res = await page.goto('https:' + url);

continue;
Expand All @@ -463,6 +467,7 @@ class Tools {
};

getOrderData = async (skuId, retry = 20) => {
if (!this.takHandle) return;
while (retry--) {
try {
console.info('生成提交抢购订单所需参数...', retry);
Expand Down Expand Up @@ -540,6 +545,11 @@ class Tools {
// 其他是同步代码不会出错
let data = this.initInfo;
if (!data) {
await this.getTakIdHandle(skuId);
if (!this.takHandle) {
console.log('TakId关键参数没获取到');
return {};
}
data = await this.getOrderData(skuId);
}
if (!data) {
Expand Down Expand Up @@ -659,7 +669,7 @@ class Tools {
// const text = await res.text();
// const text.match()
// const isSuccess = text.match(/(class="ftx-02")/i)[1];
return true
return true;
}
if (
res.url.indexOf(`https://cart.jd.com/cart_asyc_index_utf8.html`) !== -1
Expand Down

0 comments on commit 288501e

Please sign in to comment.