adding headers to each request to haifa

This commit is contained in:
Kfir Dayan 2024-02-04 13:05:18 +02:00
parent 3ad063cbc2
commit 59552698e9
2 changed files with 11 additions and 2 deletions

6
dist/GameSource.js vendored
View file

@ -14,7 +14,11 @@ class GameSource {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `https://mhaifafc.com/games?lang=en`;
console.log('Trying to get games from Haifa...'); console.log('Trying to get games from Haifa...');
try { try {
const result = await axios_1.default.get(sourceUrl); const result = await axios_1.default.get(sourceUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
});
const parsedResult = (0, node_html_parser_1.parse)(result.data.toString()); const parsedResult = (0, node_html_parser_1.parse)(result.data.toString());
const gameBoxs = parsedResult.querySelectorAll(".game-box"); const gameBoxs = parsedResult.querySelectorAll(".game-box");
const games = []; const games = [];

View file

@ -12,7 +12,12 @@ export default class GameSource {
const sourceUrl = `https://mhaifafc.com/games?lang=en`; const sourceUrl = `https://mhaifafc.com/games?lang=en`;
console.log('Trying to get games from Haifa...'); console.log('Trying to get games from Haifa...');
try { try {
const result = await axios.get(sourceUrl); const result = await axios.get(sourceUrl,
{
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
});
const parsedResult = parse(result.data.toString()); const parsedResult = parse(result.data.toString());
const gameBoxs = parsedResult.querySelectorAll(".game-box"); const gameBoxs = parsedResult.querySelectorAll(".game-box");