Zaious commited on
Commit
7a2680d
·
verified ·
1 Parent(s): 1dc5cf7

Upload product_scraper.html

Browse files
Files changed (1) hide show
  1. templates/product_scraper.html +245 -0
templates/product_scraper.html ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-TW">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Bunjang 商品資訊抓取</title>
6
+ <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;700&display=swap" rel="stylesheet">
7
+ <style>
8
+ :root {
9
+ --primary-color: #FF0000; /* 紅色 */
10
+ --secondary-color: #000000; /* 黑色 */
11
+ --background-color: #F5F5F5;
12
+ --text-color: #333;
13
+ }
14
+
15
+ * {
16
+ margin: 0;
17
+ padding: 0;
18
+ box-sizing: border-box;
19
+ }
20
+
21
+ body {
22
+ font-family: 'Noto Sans TC', sans-serif;
23
+ background-color: var(--background-color);
24
+ color: var(--text-color);
25
+ line-height: 1.6;
26
+ }
27
+
28
+ .container {
29
+ max-width: 700px;
30
+ margin: 0 auto;
31
+ padding: 20px;
32
+ background-color: white;
33
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
34
+ }
35
+
36
+ .header {
37
+ text-align: center;
38
+ margin-bottom: 20px;
39
+ color: var(--primary-color);
40
+ border-bottom: 2px solid var(--secondary-color);
41
+ padding-bottom: 10px;
42
+ }
43
+
44
+ .search-section {
45
+ display: flex;
46
+ margin-bottom: 20px;
47
+ }
48
+
49
+ #product-url {
50
+ flex-grow: 1;
51
+ padding: 10px;
52
+ border: 2px solid var(--primary-color);
53
+ margin-right: 10px;
54
+ }
55
+
56
+ .btn {
57
+ background-color: var(--primary-color);
58
+ color: white;
59
+ border: none;
60
+ padding: 10px 20px;
61
+ cursor: pointer;
62
+ transition: background-color 0.3s ease;
63
+ }
64
+
65
+ .btn:hover {
66
+ background-color: var(--secondary-color);
67
+ }
68
+
69
+ #error-message {
70
+ color: var(--primary-color);
71
+ text-align: center;
72
+ margin-bottom: 20px;
73
+ }
74
+
75
+ .product-detail {
76
+ margin-bottom: 15px;
77
+ display: flex;
78
+ align-items: center;
79
+ }
80
+
81
+ .product-detail label {
82
+ width: 180px;
83
+ font-weight: bold;
84
+ color: var(--primary-color);
85
+ }
86
+
87
+ .product-detail .value {
88
+ flex-grow: 1;
89
+ color: var(--secondary-color);
90
+ }
91
+
92
+ #product-image {
93
+ max-width: 100%;
94
+ max-height: 400px;
95
+ object-fit: contain;
96
+ margin-bottom: 20px;
97
+ border: 2px solid var(--primary-color);
98
+ background-color: #f0f0f0;
99
+ display: flex;
100
+ justify-content: center;
101
+ align-items: center;
102
+ color: var(--secondary-color);
103
+ font-weight: bold;
104
+ }
105
+
106
+ @media (max-width: 600px) {
107
+ .container {
108
+ width: 95%;
109
+ padding: 10px;
110
+ }
111
+
112
+ .product-detail {
113
+ flex-direction: column;
114
+ align-items: flex-start;
115
+ }
116
+
117
+ .product-detail label {
118
+ margin-bottom: 5px;
119
+ }
120
+ }
121
+ </style>
122
+ </head>
123
+ <body>
124
+ <div class="container">
125
+ <div class="header">
126
+ <h1>Bunjang 商品資訊抓取</h1>
127
+ </div>
128
+
129
+ <div class="search-section">
130
+ <input type="text" id="product-url" placeholder="請輸入 Bunjang 商品網址">
131
+ <button class="btn" onclick="fetchProductInfo()">抓取商品資訊</button>
132
+ <div class="form-check form-switch" style="margin-left: 10px; display: inline-block;">
133
+ <input class="form-check-input" type="checkbox" id="aiTranslationSwitch">
134
+ <label class="form-check-label" for="aiTranslationSwitch">啟用AI翻譯</label>
135
+ </div>
136
+ </div>
137
+
138
+ <div id="error-message"></div>
139
+
140
+ <div id="product-info">
141
+ <div id="product-image">待載入</div>
142
+
143
+ <div class="product-detail">
144
+ <label>商品韓文名稱</label>
145
+ <span id="product-korean-name" class="value">-</span>
146
+ </div>
147
+
148
+ <div class="product-detail">
149
+ <label>商品敘述</label>
150
+ <span id="product-description" class="value">-</span>
151
+ </div>
152
+
153
+ <div class="product-detail">
154
+ <label>商品售價(韓元)</label>
155
+ <span id="product-price" class="value">-</span>
156
+ </div>
157
+
158
+ <div class="product-detail">
159
+ <label>商品售價(台幣)</label>
160
+ <span id="product-price-twd" class="value">-</span>
161
+ </div>
162
+
163
+ <div class="product-detail">
164
+ <label>惡魔代購價(台幣)</label>
165
+ <span id="product-price-agent" class="value">-</span>
166
+ </div>
167
+ </div>
168
+ </div>
169
+
170
+ <script>
171
+ function normalizeUrl(url) {
172
+ // 檢查是否��� globalbunjang.com 的網址
173
+ const globalBunjangRegex = /^https?:\/\/(?:www\.)?globalbunjang\.com\/product\/(\d+)/i;
174
+ const match = url.match(globalBunjangRegex);
175
+
176
+ if (match) {
177
+ // 如果是 globalbunjang.com,轉換為 m.bunjang.co.kr 的格式
178
+ return `https://m.bunjang.co.kr/products/${match[1]}`;
179
+ }
180
+
181
+ // 如果不是 globalbunjang.com,直接返回原始 URL
182
+ return url;
183
+ }
184
+
185
+ async function fetchProductInfo() {
186
+ let url = document.getElementById('product-url').value;
187
+ const errorMessage = document.getElementById('error-message');
188
+ const productImage = document.getElementById('product-image');
189
+ const productKoreanName = document.getElementById('product-korean-name');
190
+ const productDescription = document.getElementById('product-description');
191
+ const productPrice = document.getElementById('product-price');
192
+ const productPriceTWD = document.getElementById('product-price-twd');
193
+ const productPriceAgent = document.getElementById('product-price-agent');
194
+
195
+ // 標準化 URL
196
+ url = normalizeUrl(url);
197
+ // 更新輸入框中的 URL
198
+ document.getElementById('product-url').value = url;
199
+
200
+ // 清除之前的資訊和錯誤
201
+ errorMessage.textContent = '';
202
+ productImage.textContent = '待載入';
203
+ productKoreanName.textContent = '-';
204
+ productDescription.textContent = '-';
205
+ productPrice.textContent = '-';
206
+ productPriceTWD.textContent = '-';
207
+ productPriceAgent.textContent = '-';
208
+
209
+ try {
210
+ const response = await fetch('/scrape', {
211
+ method: 'POST',
212
+ headers: {
213
+ 'Content-Type': 'application/json',
214
+ },
215
+ body: JSON.stringify({ url: url })
216
+ });
217
+
218
+ const data = await response.json();
219
+
220
+ if (response.ok) {
221
+ productImage.innerHTML = data.image
222
+ ? `<img src="${data.image}" alt="商品圖片" style="max-width: 100%; max-height: 400px; object-fit: contain;">`
223
+ : '無圖片';
224
+
225
+ productKoreanName.textContent = data.korean_name || '-';
226
+ productDescription.textContent = data.description || '無商品描述';
227
+
228
+ const price = parseFloat(data.price);
229
+ productPrice.textContent = `${data.price} ${data.currency}`;
230
+ productPriceTWD.innerHTML = `${(price * 0.025).toFixed(2)} 台幣 <small style="color: #888; font-size: 0.8em;">(=韓元*0.025)</small>`;
231
+ productPriceAgent.innerHTML = `${(price / 31.5).toFixed(2)} 台幣<br><small style="color: #888; font-size: 0.8em;">(=韓元/31.5含國際運費、未確認韓國國內運費,僅為估算實際請按惡魔代購報價)</small>`;
232
+ } else {
233
+ errorMessage.textContent = data.error || '抓取資訊時發生錯誤';
234
+ }
235
+ } catch (error) {
236
+ console.error('Error:', error);
237
+ errorMessage.textContent = '抓取資訊時發生錯誤。請檢查網址是否正確,或稍後再試。';
238
+ }
239
+ }
240
+ </script>
241
+ <footer style="text-align: center; color: #333; font-size: 0.8em; margin-top: 20px; padding: 10px; background-color: #f4f4f4;">
242
+ 本商品資料擷取網頁由 <a href="https://www.plurk.com/avaritia_the_demon" target="_blank" style="color: #333; text-decoration: underline;">惡魔代購 Avaritia_the_demon @ Plurk</a> 製作,有代購需求歡迎聯繫。
243
+ </footer>
244
+ </body>
245
+ </html>