Spaces:
Paused
Paused
File size: 5,685 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | const axios = require('axios');
const fs = require('fs');
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'
];
const referrers = [
'https://www.1688.com/',
'https://s.1688.com/',
'https://search.1688.com/',
'https://detail.1688.com/'
];
function getRandomHeaders() {
const randomUserAgent = userAgents[Math.floor(Math.random() * userAgents.length)];
const randomReferrer = referrers[Math.floor(Math.random() * referrers.length)];
return {
'User-Agent': randomUserAgent,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1',
'Referer': randomReferrer
};
}
async function analyzeCategoryPage() {
try {
const categoryUrl = 'https://s.1688.com/selloffer/offer_search.htm?spm=a260k.home2025.category.dL2.66333597RpQZVA&charset=utf8&keywords=%E5%A5%B3%E8%A3%85&featurePair=401:33613523,401:8872005&beginPage=1';
console.log('π Analyzing 1688 category page for API endpoints...');
await delay(2000 + Math.random() * 3000);
// Fetch the category page
const response = await axios.get(categoryUrl, {
headers: getRandomHeaders(),
timeout: 15000
});
console.log('β
Page fetched successfully!');
const html = response.data;
fs.writeFileSync('category-analysis.html', html);
// Look for common API patterns in 1688
const apiPatterns = [
'h5api',
'offerList',
'productData',
'window.data',
'jsonp',
'callback',
'data.offers',
'searchResult',
'sm-offer'
];
console.log('\nπ Searching for API patterns in the HTML:');
const lines = html.split('\n');
const apiCandidates = [];
lines.forEach((line, index) => {
apiPatterns.forEach(pattern => {
if (line.includes(pattern)) {
const cleanLine = line.trim().substring(0, 200);
apiCandidates.push({
line: index + 1,
pattern: pattern,
content: cleanLine
});
}
});
});
// Display found patterns
if (apiCandidates.length > 0) {
console.log('\nπ Found potential API patterns:');
apiCandidates.slice(0, 10).forEach(candidate => {
console.log(`Line ${candidate.line}: [${candidate.pattern}] ${candidate.content}`);
});
} else {
console.log('β No obvious API patterns found in HTML');
}
// Look for script tags with data
const scriptTags = html.match(/<script[^>]*>[\s\S]*?<\/script>/gi) || [];
const dataScripts = scriptTags.filter(script =>
script.includes('data') || script.includes('offer') || script.includes('product')
);
console.log('\nπ Found', dataScripts.length, 'script tags with potential data');
// Extract URLs from script tags
const urlPatterns = [
/https?:\/\/[^"'\s]*\.(json|jsonp|js)[^"'\s]*/gi,
/https?:\/\/[^"'\s]*\.(1688|alibaba)[^"'\s]*/gi,
/https?:\/\/[^"'\s]*\/api\/[^"'\s]*/gi
];
const foundUrls = new Set();
dataScripts.forEach(script => {
urlPatterns.forEach(pattern => {
const matches = script.match(pattern) || [];
matches.forEach(url => foundUrls.add(url));
});
});
console.log('\nπ Found potential API URLs:');
Array.from(foundUrls).slice(0, 5).forEach(url => {
console.log(' ', url);
});
// Test common 1688 API endpoints
const commonEndpoints = [
'https://h5api.m.1688.com/h5/mtop.1688.search.suggest/1.0/',
'https://h5api.m.1688.com/h5/mtop.1688.search.offerResult/1.0/',
'https://s.1688.com/selloffer/search_offer_result.json'
];
console.log('\nπ§ͺ Testing common 1688 API endpoints...');
for (const endpoint of commonEndpoints) {
try {
await delay(1000 + Math.random() * 2000);
console.log('Testing:', endpoint);
const apiResponse = await axios.get(endpoint, {
headers: getRandomHeaders(),
timeout: 8000,
params: {
keywords: 'ε₯³θ£
',
beginPage: 1,
spm: 'a260k.home2025.category.dL2.66333597RpQZVA'
}
});
console.log('β
Response status:', apiResponse.status);
console.log('Content type:', apiResponse.headers['content-type']);
console.log('Data length:', apiResponse.data?.length || 'No data');
if (typeof apiResponse.data === 'object') {
console.log('Data keys:', Object.keys(apiResponse.data));
}
} catch (error) {
console.log('β Failed:', error.message);
}
console.log('---');
}
console.log('\nπ― Analysis complete! Check category-analysis.html for detailed HTML');
} catch (error) {
console.error('β Analysis failed:', error.message);
}
}
analyzeCategoryPage(); |