refactor: reorganize scripts - move debug code to experiments/
- Move debug/test scripts from src/scripts/ to experiments/ - Remove test-detail-endpoint from package.json - Delete temp-product-page.html - Move E2E_GUIDE.md to docs/ - Add experiments/README.md with documentation - Keep only production scripts in src/scripts/ - Clean up tsconfig.json exclude list (experiments are now outside src/) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
81
experiments/magnit-detail-endpoints/debug-detail-response.ts
Normal file
81
experiments/magnit-detail-endpoints/debug-detail-response.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'dotenv/config';
|
||||
import { chromium } from 'playwright';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../utils/logger.js';
|
||||
|
||||
async function main() {
|
||||
Logger.info('=== Debug: Смотрим что возвращает API ===\n');
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
await page.goto('https://magnit.ru/', { waitUntil: 'domcontentloaded' });
|
||||
const cookies = await context.cookies();
|
||||
const cookieStr = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
||||
|
||||
const mgUdiCookie = cookies.find(c => c.name === 'mg_udi');
|
||||
const deviceId = mgUdiCookie?.value || '';
|
||||
|
||||
const httpClient = axios.create({
|
||||
baseURL: 'https://magnit.ru',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': '*/*',
|
||||
'Cookie': cookieStr,
|
||||
'x-device-id': deviceId,
|
||||
'x-client-name': 'magnit',
|
||||
'x-device-platform': 'Web',
|
||||
'x-new-magnit': 'true',
|
||||
},
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
|
||||
// Тестируем на конкретном товаре из логов
|
||||
const productId = '1000201813'; // Презервативы Durex - там был brand
|
||||
|
||||
const endpoint = `/webgate/v2/goods/${productId}/stores/992301?storetype=2&catalogtype=1`;
|
||||
|
||||
Logger.info(`Запрос: ${endpoint}`);
|
||||
|
||||
try {
|
||||
const response = await httpClient.get(endpoint);
|
||||
Logger.info(`Status: ${response.status}\n`);
|
||||
|
||||
const data = response.data;
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
|
||||
// Анализируем что есть в ответе
|
||||
if (data.details && data.details.length > 0) {
|
||||
Logger.info(`\n=== АНАЛИЗ details массива (${data.details.length} элементов) ===\n`);
|
||||
|
||||
for (let i = 0; i < Math.min(data.details.length, 15); i++) {
|
||||
const detail = data.details[i];
|
||||
Logger.info(`${i + 1}. name: "${detail.name}" | value: "${detail.value}"`);
|
||||
|
||||
// Проверяем парсинг
|
||||
const name = detail.name.toLowerCase();
|
||||
|
||||
if (name.includes('бренд') || name === 'brand') {
|
||||
Logger.info(` → Это БРЕНД!`);
|
||||
} else if (name.includes('описание') || name === 'description') {
|
||||
Logger.info(` → Это ОПИСАНИЕ!`);
|
||||
} else if (name.includes('вес') || name.includes('weight')) {
|
||||
Logger.info(` → Это ВЕС!`);
|
||||
} else if (name.includes('единица') || name.includes('unit')) {
|
||||
Logger.info(` → Это ЕДИНИЦА!`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.categories && data.categories.length > 0) {
|
||||
Logger.info(`\nCategories: ${data.categories.join(', ')}`);
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
Logger.error('Ошибка:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user