我得到一個
參考錯誤:終端 A 未定義
在第 48 行。我不確定我做錯了什么。
writeStream.write(`Terminal A,Terminal B,Terminal C/D \n`);
var minutes = 1, timerInerval = minutes * 60 * 1000;
function TerminalOccupancyData() {
request('https://www.laguardiaairport.com/to-from-airport/parking', (error, response, html) => {
// Check there is no error
if (!error && response.statusCode == 200) {
// using cheerio library to load the website page html
const $ = cheerio.load(html);
$('.terminal-left').each((span, el) => {
// Find the element using the class
const terminalA = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
const terminalB = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
const terminalCD = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
});
console.log('\nTerminal Data scraped ... \n');
}
});
// Export to file to upload to database
writeStream.write(`${terminalA},${terminalB},${terminalCD} \n`);
}
setInterval(TerminalOccupancyData, timerInerval);
uj5u.com熱心網友回復:
您在這里遇到的問題是您writeStream.write(...)與它參考的變數不在同一范圍內。由于您沒有嘗試從外部函式回傳任何值,我相信可以解決您的問題的方法只是將該陳述句移動到.each()回呼函式中,如下所示:
function TerminalOccupancyData() {
request('https://www.laguardiaairport.com/to-from-airport/parking', (error, response, html) => {
// Check there is no error
if (!error && response.statusCode == 200) {
// using cheerio library to load the website page html
const $ = cheerio.load(html);
$('.terminal-left').each((span, el) => {
// Find the element using the class
const terminalA = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
const terminalB = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
const terminalCD = $(el)
.find('.terminal-percentage')
.text()
.replace(/% Full/, '');
// Export to file to upload to database
writeStream.write(`${terminalA},${terminalB},${terminalCD} \n`);
});
console.log('\nTerminal Data scraped ... \n');
}
});
}
setInterval(TerminalOccupancyData, timerInerval);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/359250.html
上一篇:如何在aspnetcorewebAPI上正確地將串列轉換為IQueryable
下一篇:將3列轉換為2列-Python
