Web Scraping Stock Prices Using Regular Expressions … Look-Behind & Look-Ahead Methods
let STOCKS_NASDAQ = ['NVDA','TSLA', 'AMZN'];
async function func_lookupStock(stock){
const URL = `https://www.google.com/finance/quote/${stock}:NASDAQ`;
let response = await fetch(URL);
let HTML = await response.text();
let lookB = '(?❮=data-last-price=\")';
let lookA = '(?=\" data-last-normal-market-timestamp)';
let priceMatch = HTML.match(lookB + '.*?' + lookA)[0];
return priceMatch
}
// Main Function
(async() =❯ {
let arrayPromise1 = STOCKS_NASDAQ.map(stock =❯ func_lookupStock(stock));
let arr_stock = await Promise.all(arrayPromise1);
console.log(arr_stock);
})()
--------------------------------------------------------------------------
Practice / Explaination (https://regex101.com)
Regular Expression (RE) Examples:
--------------------------------------------------------------------------
. any 1 character
.? any 0 or 1 character
[0-9] any 1 number character
[a-Z] any 1 letter character
[^3] any 1 character except 3
^123$ newline starts with 1, then 2, then newline ends with 3
.{3-4} any 3 to 4 characters
.* any 0 or more characters
.+ any 1 or more characters
.*? any 0 or more non-greedy characters
(dog | cat) either dog or cat group characters
\ escape character for ( " . \ ^ $ * + ? ... more )
(?❮=123) lookbehind for 123 group characters
(?=678) lookahead for 678 group characters
(?❮=123)..(?=678) will return 45 for (example data: 12345678)
-----------------------
DONATE:
-----------------------
PAT: https://www.patreon.com/rezatahirkheli
PP: https://www.paypal.com/paypalme/rezatahirkheli
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
Видео Web Scraping Stock Prices Using Regular Expressions … Look-Behind & Look-Ahead Methods канала ZeroLife
async function func_lookupStock(stock){
const URL = `https://www.google.com/finance/quote/${stock}:NASDAQ`;
let response = await fetch(URL);
let HTML = await response.text();
let lookB = '(?❮=data-last-price=\")';
let lookA = '(?=\" data-last-normal-market-timestamp)';
let priceMatch = HTML.match(lookB + '.*?' + lookA)[0];
return priceMatch
}
// Main Function
(async() =❯ {
let arrayPromise1 = STOCKS_NASDAQ.map(stock =❯ func_lookupStock(stock));
let arr_stock = await Promise.all(arrayPromise1);
console.log(arr_stock);
})()
--------------------------------------------------------------------------
Practice / Explaination (https://regex101.com)
Regular Expression (RE) Examples:
--------------------------------------------------------------------------
. any 1 character
.? any 0 or 1 character
[0-9] any 1 number character
[a-Z] any 1 letter character
[^3] any 1 character except 3
^123$ newline starts with 1, then 2, then newline ends with 3
.{3-4} any 3 to 4 characters
.* any 0 or more characters
.+ any 1 or more characters
.*? any 0 or more non-greedy characters
(dog | cat) either dog or cat group characters
\ escape character for ( " . \ ^ $ * + ? ... more )
(?❮=123) lookbehind for 123 group characters
(?=678) lookahead for 678 group characters
(?❮=123)..(?=678) will return 45 for (example data: 12345678)
-----------------------
DONATE:
-----------------------
PAT: https://www.patreon.com/rezatahirkheli
PP: https://www.paypal.com/paypalme/rezatahirkheli
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
Видео Web Scraping Stock Prices Using Regular Expressions … Look-Behind & Look-Ahead Methods канала ZeroLife
Комментарии отсутствуют
Информация о видео
28 июня 2025 г. 3:48:18
00:17:19
Другие видео канала