Javascript 是否可以使用中断跳出或跳过爬网功能?

Javascript 是否可以使用中断跳出或跳过爬网功能?,javascript,node.js,database,web-scraping,web-crawler,Javascript,Node.js,Database,Web Scraping,Web Crawler,您好,我想知道在第一次运行脚本后,是否可以使用“break”或任何其他方法跳过爬网功能,并在下一个用户请求中仅使用包含爬网信息的数组变量 let glossary = []; /** Initialise crawling and save it into glossary array */ function init() { const glossary_url = 'https://xxxx'; const headers = { cookie:

您好,我想知道在第一次运行脚本后,是否可以使用“break”或任何其他方法跳过爬网功能,并在下一个用户请求中仅使用包含爬网信息的数组变量

let glossary = [];  

/** Initialise crawling and save it into glossary array */
function init() {
    const glossary_url = 'https://xxxx';

     const headers = {
         cookie: 'cookies:kdkjslkd424'  
     };

    const options = {
        url: glossary_url,
        method: 'GET',
        headers: headers
    };

    request(options, function (error, response, body) {
        const newDom = new jsdom(body);
        const $ = require('jquery')(newDom.window);

        $('ul > li > span[style="line-height:1.6;"]').each(function (index, element) {
            let text = element.textContent.trim(); // Get text from html
            let splitText = text.split(' = '); // split text by =
            //console.log(text);


            if (splitText.length > 1) {
                glossary.push({
                    key: splitText[0].trim(),
                    value: splitText[1],
                    value2: splitText[2]
                });
            }
        });
        //console.log(glossary);

        findMatch('DPDL');
    });
}
 break init;

function findMatch (key){
    for(i = 0; i < glossary.length ; i++) {
        if (glossary[i].key === key){
            // console.log (glossary[i].value );
            // console.log(glossary[i].key);
            // console.log(glossary[i].value2);
            // console.log(key);
            console.log(key + ' = ' + glossary[i].value + ' ' + glossary[i].value2 );
        } 
    } 

}


init();  
let glossary=[];
/**初始化爬网并将其保存到词汇表数组中*/
函数init(){
常量词汇表https://xxxx';
常量头={
cookie:'cookies:kdkjslkd424'
};
常量选项={
url:glossary\uURL,
方法:“GET”,
标题:标题
};
请求(选项、功能(错误、响应、正文){
const newDom=新的jsdom(body);
const$=require('jquery')(newDom.window);
$('ul>li>span[style=“line height:1.6;”“])。每个(函数(索引,元素){
let text=element.textContent.trim();//从html获取文本
让splitText=text.split('=');//按=
//console.log(文本);
如果(splitText.length>1){
推送({
键:拆分文本[0]。修剪(),
值:splitText[1],
值2:拆分文本[2]
});
}
});
//console.log(词汇表);
findMatch(“DPDL”);
});
}
中断初始化;
功能findMatch(键){
对于(i=0;i

如果用户希望搜索另一个值,则中断或跳过爬网函数,该值将仅在词汇表数组glossary=[]中找到,而不会再次爬网,因为这需要很长时间

break init
。。。无效-请参阅-您可以“断开”到“标签”-但是,由于
init
只调用一次,我看不出你有什么问题is@JaromandaX我试图做的是多次获取用户输入值,并在词汇表数组中搜索该值,以便更快地给出结果,而不是在每次用户想要查找新值/输入时对页面进行爬网。。。。