Spaces:
Running
Running
Download index.html from Battingchart300/html-extractor: direct link, hf CLI and curl.
- Browser
- Download file 8.43 kB
-
https://huggingface.co/spaces/Battingchart300/html-extractor/resolve/main/index.html
- Command line
-
hf download hf://spaces/Battingchart300/html-extractor/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Battingchart300/html-extractor/resolve/main/index.html
8.43 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>HTML Data Extractor</title> | |
| <style> | |
| :root { --p: #00f0ff; --bg: #07070c; --panel: #12121c; --line: rgba(255,255,255,.12); } | |
| * { box-sizing: border-box; margin: 0; padding: 0; } | |
| body { background: var(--bg); color: #eee; font-family: 'Segoe UI', Arial, sans-serif; padding: 24px; } | |
| .wrap { max-width: 860px; margin: 0 auto; } | |
| h1 { font-size: 26px; margin-bottom: 6px; } | |
| h1 span { color: var(--p); } | |
| p.sub { color: #9aa; margin-bottom: 20px; } | |
| .card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; } | |
| label { display: block; font-size: 13px; color: #aaa; margin: 12px 0 4px; } | |
| label:first-child { margin-top: 0; } | |
| select, textarea { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: #0a0a12; color: #fff; font-size: 14px; } | |
| textarea { min-height: 160px; font-family: Consolas, monospace; font-size: 13px; resize: vertical; } | |
| .row { display: flex; gap: 12px; } | |
| .row > div { flex: 1; } | |
| pre { background: #0a0a12; border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; font-size: 13px; line-height: 1.5; white-space: pre; margin-top: 8px; } | |
| h2 { font-size: 16px; margin-bottom: 4px; } | |
| .btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; } | |
| button { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #1c1c2a; color: #fff; cursor: pointer; font-size: 14px; } | |
| button.primary { background: var(--p); color: #000; border-color: var(--p); font-weight: 700; } | |
| button:hover { opacity: .85; } | |
| .note { color: #888; font-size: 13px; margin-top: 14px; } | |
| .status { color: #9aa; font-size: 13px; margin-top: 8px; } | |
| table.preview { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; } | |
| table.preview th, table.preview td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; } | |
| table.preview th { background: #1c1c2a; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="wrap"> | |
| <h1>HTML Data <span>Extractor</span></h1> | |
| <p class="sub">Paste HTML, get a table back as CSV or JSON. No fetching, no server — everything runs in your browser, on HTML you paste yourself.</p> | |
| <div class="card"> | |
| <div class="row"> | |
| <div> | |
| <label for="mode">Extract</label> | |
| <select id="mode"> | |
| <option value="tables">Tables (<table>)</option> | |
| <option value="links">Links (<a href>)</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="tablePick">Table</label> | |
| <select id="tablePick"></select> | |
| </div> | |
| </div> | |
| <label for="input">Your HTML</label> | |
| <textarea id="input" placeholder="<table><tr><th>Name</th><th>Price</th></tr><tr><td>Widget</td><td>9.99</td></tr></table>"></textarea> | |
| <div class="btns"> | |
| <button class="primary" onclick="extract()">Extract</button> | |
| <button onclick="loadSample()">Load sample</button> | |
| <button onclick="clearAll()">Clear</button> | |
| </div> | |
| <p class="status" id="status"></p> | |
| </div> | |
| <div class="card" id="result-card" style="display:none"> | |
| <h2>Preview</h2> | |
| <div id="preview"></div> | |
| <h2 style="margin-top:16px">CSV</h2> | |
| <pre id="out-csv"></pre> | |
| <h2 style="margin-top:16px">JSON</h2> | |
| <pre id="out-json"></pre> | |
| <div class="btns"> | |
| <button class="primary" onclick="copyText('out-csv')">Copy CSV</button> | |
| <button onclick="downloadText('out-csv', 'extracted.csv')">Download CSV</button> | |
| <button onclick="copyText('out-json')">Copy JSON</button> | |
| <button onclick="downloadText('out-json', 'extracted.json')">Download JSON</button> | |
| </div> | |
| </div> | |
| <p class="note">Tip: paste only HTML you are allowed to use — your own pages, or pages made for practice such as quotes.toscrape.com. This tool never fetches a URL by itself.</p> | |
| </div> | |
| <script> | |
| function escapeCsv(v) { | |
| v = String(v == null ? '' : v); | |
| return /[",\n]/.test(v) ? '"' + v.replace(/"/g, '""') + '"' : v; | |
| } | |
| function rowsToCSV(rows) { | |
| return rows.map(function (r) { return r.map(escapeCsv).join(','); }).join('\n'); | |
| } | |
| function rowsToJSON(rows) { | |
| if (!rows.length) return '[]'; | |
| var head = rows[0]; | |
| return JSON.stringify(rows.slice(1).map(function (r) { | |
| var o = {}; | |
| head.forEach(function (h, i) { o[h || ('col' + (i + 1))] = r[i] == null ? '' : r[i]; }); | |
| return o; | |
| }), null, 2); | |
| } | |
| function tableRows(table) { | |
| var out = []; | |
| var trs = table.querySelectorAll('tr'); | |
| trs.forEach(function (tr) { | |
| var cells = tr.querySelectorAll('th, td'); | |
| if (cells.length) out.push(Array.prototype.map.call(cells, function (c) { return c.textContent.trim(); })); | |
| }); | |
| return out; | |
| } | |
| function loadSample() { | |
| document.getElementById('input').value = | |
| '<table>\n <tr><th>Name</th><th>Price</th><th>In stock</th></tr>\n' + | |
| ' <tr><td>Widget A</td><td>9.99</td><td>yes</td></tr>\n' + | |
| ' <tr><td>Widget B</td><td>14.50</td><td>no</td></tr>\n</table>'; | |
| extract(); | |
| } | |
| function clearAll() { | |
| document.getElementById('input').value = ''; | |
| document.getElementById('result-card').style.display = 'none'; | |
| document.getElementById('status').textContent = ''; | |
| } | |
| function showRows(rows, label) { | |
| var card = document.getElementById('result-card'); | |
| if (!rows.length) { | |
| card.style.display = 'none'; | |
| document.getElementById('status').textContent = label; | |
| return; | |
| } | |
| card.style.display = 'block'; | |
| document.getElementById('status').textContent = rows.length + ' rows found.'; | |
| var html = '<table class="preview">'; | |
| rows.forEach(function (r, i) { | |
| html += '<tr>' + r.map(function (c) { | |
| var tag = i === 0 ? 'th' : 'td'; | |
| return '<' + tag + '>' + String(c).replace(/&/g, '&').replace(/</g, '<') + '</' + tag + '>'; | |
| }).join('') + '</tr>'; | |
| }); | |
| document.getElementById('preview').innerHTML = html + '</table>'; | |
| document.getElementById('out-csv').textContent = rowsToCSV(rows); | |
| document.getElementById('out-json').textContent = rowsToJSON(rows); | |
| } | |
| var lastDoc = null; | |
| function extract() { | |
| var html = document.getElementById('input').value; | |
| var mode = document.getElementById('mode').value; | |
| var pick = document.getElementById('tablePick'); | |
| if (!html.trim()) { | |
| document.getElementById('status').textContent = 'Paste some HTML first — or press "Load sample".'; | |
| return; | |
| } | |
| lastDoc = new DOMParser().parseFromString(html, 'text/html'); | |
| if (mode === 'links') { | |
| var links = Array.prototype.map.call(lastDoc.querySelectorAll('a[href]'), function (a) { | |
| return [a.textContent.trim(), a.getAttribute('href')]; | |
| }); | |
| showRows([['text', 'href']].concat(links), 'No links found in this HTML.'); | |
| pick.innerHTML = ''; | |
| return; | |
| } | |
| var tables = lastDoc.querySelectorAll('table'); | |
| if (!tables.length) { | |
| showRows([], 'No <table> found in this HTML. Try "Links" mode, or paste HTML that contains a table.'); | |
| pick.innerHTML = ''; | |
| return; | |
| } | |
| pick.innerHTML = ''; | |
| tables.forEach(function (t, i) { | |
| var opt = document.createElement('option'); | |
| opt.value = i; | |
| opt.textContent = 'Table ' + (i + 1) + ' — ' + t.querySelectorAll('tr').length + ' rows'; | |
| pick.appendChild(opt); | |
| }); | |
| showRows(tableRows(tables[Number(pick.value) || 0]), ''); | |
| } | |
| function copyText(id) { | |
| var t = document.getElementById(id).textContent; | |
| if (navigator.clipboard) navigator.clipboard.writeText(t); | |
| } | |
| function downloadText(id, name) { | |
| var t = document.getElementById(id).textContent; | |
| var a = document.createElement('a'); | |
| a.href = URL.createObjectURL(new Blob([t], { type: 'text/plain' })); | |
| a.download = name; a.click(); | |
| } | |
| document.getElementById('mode').addEventListener('change', function () { | |
| document.getElementById('tablePick').disabled = this.value === 'links'; | |
| if (document.getElementById('input').value.trim()) extract(); | |
| }); | |
| document.getElementById('tablePick').addEventListener('change', function () { | |
| if (!lastDoc) return; | |
| var tables = lastDoc.querySelectorAll('table'); | |
| showRows(tableRows(tables[Number(this.value) || 0]), ''); | |
| }); | |
| if (typeof module !== 'undefined') { module.exports = { escapeCsv: escapeCsv, rowsToCSV: rowsToCSV, rowsToJSON: rowsToJSON }; } | |
| </script> | |
| </body> | |
| </html> | |