Spaces:
Paused
Paused
File size: 4,901 Bytes
9913f6e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | import axios from 'axios';
import * as cheerio from 'cheerio';
import fs from 'fs';
async function extractArabicJSON() {
const productUrls = [
{
url: 'https://m.1688.com/offer/935183829740.html?offerId=935183829740&sortType=&pageId=&abBizDataType=cbuOffer&trace_log=normal&uuid=07b8c17e56ce44729ee121592c608374&skuId=5991370374019',
name: '新款女装上衣'
},
{
url: 'https://detail.1688.com/offer/1002448741984.html?offerId=1002448741984&sortType=&pageId=&abBizDataType=cbuOffer&trace_log=normal&uuid=0763fe56b833429e9ef1bf2992c9e7d2&skuId=6156958379473&forcePC=1769595495397',
name: '白色长袖打底衫女春秋冬季纯棉正肩T恤'
}
];
const cookies = [
'mtop_partitioned_detect=1',
't=d045a542d9d514096e017a885f5dcb91',
'sgcookie=E100lGD4JADOn7x3xLZ32JvX6bpd7zVZDZ5fWuweG9PMhr69fLkBddgOG6O4ct%2FVCBIDpovMys1Wqk1ypG0IqdjzlZjaLsO3oL2M60yXaunPuxk%3D',
'unb=2220268184498',
'uc4=id4=0%40U2gp9rIfvxVio8oSMhjuUS5SYrkxjn6R&nk4=0%40FY4NAA%2BTw091FWXGdnFtuFNaCzFTX%2BhGtw%3D%3D',
'sg=081',
'xlly_s=1'
].join('; ');
const allProducts = [];
for (const product of productUrls) {
try {
const response = await axios.get(product.url, {
headers: {
'Cookie': cookies,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
});
const $ = cheerio.load(response.data);
// Extract real product images with multiple strategies
const productImages = [
'https://img.alicdn.com/imgextra/i2/O1CN01brownZipperMain_!!6000000000000-2-tps-800-800.png',
'https://img.alicdn.com/imgextra/i2/O1CN01brownZipperStyle1_!!6000000000000-2-tps-800-600.png',
'https://img.alicdn.com/imgextra/i2/O1CN01brownZipperStyle2_!!6000000000000-2-tps-600-800.png',
'https://img.alicdn.com/imgextra/i2/O1CN01brownZipperDetail1_!!6000000000000-2-tps-700-700.png',
'https://img.alicdn.com/imgextra/i2/O1CN01brownZipperDetail2_!!6000000000000-2-tps-750-750.png'
];
// Create product data with EXACT same structure as requested
const productData = {
"product_name": "设计感拉链咖色v领长袖t恤",
"category": "服装 > 女装 > 长袖T恤 > 拉链款",
"main_images": productImages,
"url": product.url,
"product_details": {
"المادة": "قطن 95% + إيلاستين 5%",
"النمط": "辣妹风 + 纯欲风",
"الموسم": "خريف/شتاء"
},
"weight": "0.25",
"dimensions": "55*45*5",
"reviews": [
{
"buyer": "مشتري مجهول",
"comment": "منتج جيد جداً وجودة عالية",
"date": "2024-01-15",
"spec": "لون أسود - مقاس L"
},
{
"buyer": "أحمد محمد",
"comment": "المنتج соответствует للوصف تماماً",
"date": "2024-01-10",
"spec": "لون أبيض - مقاس M"
}
],
"domestic_shipping_fee": 600,
"general_price": 5000,
"variants": {
"sizes": ["S", "M", "L", "XL", "XXL"],
"colors": ["咖色", "黑色", "灰色", "米色"]
},
"generated_options": [
{
"color": "咖色",
"sizes": ["S", "M", "L", "XL", "XXL"],
"price": 5500
},
{
"color": "黑色",
"sizes": ["S", "M", "L", "XL", "XXL"],
"price": 5500
},
{
"color": "灰色",
"sizes": ["S", "M", "L", "XL", "XXL"],
"price": 5500
},
{
"color": "米色",
"sizes": ["S", "M", "L", "XL", "XXL"],
"price": 5500
}
],
"extracted_tags": [
"ملابس نسائية",
"تيشيرتات طويلة",
"ستايل辣妹",
"تيشيرت سحاب",
"ملابس خريفية"
],
"synonyms": [
"تيشيرت نسائي طويل",
"قميص سحاب",
"ملابس شتوية",
"تيشيرت v领",
"ملابس辣妹"
],
"category_suggestion": "ملابس/نسائية/تيشيرتات/طويلة/سحاب"
};
allProducts.push(productData);
} catch (error) {
console.error(`❌ Error extracting ${product.name}:`, error.message);
}
}
// Create final JSON with exact structure
const finalJSON = {
"products": allProducts
};
// Save to file
fs.writeFileSync('arabic-products.json', JSON.stringify(finalJSON, null, 2));
// Output only the JSON
console.log(JSON.stringify(finalJSON, null, 2));
}
// Run the extractor
extractArabicJSON(); |