File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ function detectLanguageFromHtml($) {
155155// 获取页面标题和语言
156156async function getPageTitleAndLang ( url ) {
157157 let browser ;
158+ let page ;
158159
159160 try {
160161 browser = await puppeteer . launch ( {
@@ -167,7 +168,7 @@ async function getPageTitleAndLang(url) {
167168 ] ,
168169 } ) ;
169170
170- const page = await browser . newPage ( ) ;
171+ page = await browser . newPage ( ) ;
171172
172173 await page . setUserAgent ( 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' ) ;
173174
@@ -247,6 +248,13 @@ async function getPageTitleAndLang(url) {
247248 title : url . split ( "/" ) . pop ( ) || url ,
248249 lang,
249250 } ;
251+ } finally {
252+ try {
253+ if ( page ) await page . close ( ) ;
254+ } catch ( _ ) { }
255+ try {
256+ if ( browser ) await browser . close ( ) ;
257+ } catch ( _ ) { }
250258 }
251259}
252260
@@ -341,6 +349,7 @@ async function main() {
341349
342350 // 保存到 JSON(写入 contents/static/json)
343351 saveToJsonFile ( updatedData , "static/json/baidu_tongji_data.json" ) ;
352+ process . exit ( 0 ) ;
344353 } catch ( error ) {
345354 process . exit ( 1 ) ;
346355 }
You can’t perform that action at this time.
0 commit comments