|
const http = require('http'); |
|
const https = require('https'); |
|
|
|
const url = 'https://d000d.com/e/9b3w45p3h2gz'; |
|
|
|
const headers = { |
|
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0', |
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', |
|
'Accept-Language': 'en-US,en;q=0.5', |
|
'DNT': '1', |
|
'Sec-GPC': '1', |
|
'Connection': 'keep-alive', |
|
'Cookie': 'file_id=66308942; aff=37046; ref_url=; lang=1', |
|
'Upgrade-Insecure-Requests': '1', |
|
'Sec-Fetch-Dest': 'document', |
|
'Sec-Fetch-Mode': 'navigate', |
|
'Sec-Fetch-Site': 'cross-site', |
|
'Priority': 'u=1', |
|
'Pragma': 'no-cache', |
|
'Cache-Control': 'no-cache' |
|
}; |
|
|
|
const options = { |
|
method: 'GET', |
|
headers: headers |
|
}; |
|
|
|
const fetchPage = (url) => { |
|
const client = url.startsWith('https') ? https : http; |
|
|
|
client.get(url, options, (res) => { |
|
let data = ''; |
|
|
|
if (res.statusCode !== 200) { |
|
console.error(`Failed to fetch the page. Status code: ${res.statusCode}`); |
|
return; |
|
} |
|
|
|
res.on('data', (chunk) => { |
|
data += chunk; |
|
}); |
|
|
|
res.on('end', () => { |
|
console.log('Page content fetched successfully.'); |
|
console.log(data); |
|
}); |
|
}).on('error', (err) => { |
|
console.error(`An error occurred while requesting ${url}.`); |
|
console.error(`Exception: ${err.message}`); |
|
}); |
|
}; |
|
|
|
fetchPage(url); |
|
|