Spaces:
Paused
Paused
Download server/scripts/arabic-json-extractor.js from shanshal66/chinak2: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/spaces/shanshal66/chinak2/resolve/main/server/scripts/arabic-json-extractor.js
- Command line
-
hf download hf://spaces/shanshal66/chinak2/server/scripts/arabic-json-extractor.js
-
curl -L -o arabic-json-extractor.js https://huggingface.co/spaces/shanshal66/chinak2/resolve/main/server/scripts/arabic-json-extractor.js
4.9 kB
| 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(); |