-
Notifications
You must be signed in to change notification settings - Fork 2
/
hextractor.html
232 lines (227 loc) · 7 KB
/
hextractor.html
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML Extraction Testing Ground</title>
<style>
body, html, .pane-wrapper {
font-family: sans-serif;
font-size: small;
min-height: calc(100vh - 20px);
}
.pane-wrapper {
display: flex;
flex-flow: row wrap;
justify-content: center;
}
.pane {
min-width: 350px;
display: flex;
flex-flow: column wrap;
align-items: center;
max-width: calc(50% - 20px);
}
#left.pane {
flex-grow: 0.75;
/*max-width: 600px;*/
margin-right: 20px;
}
#right.pane {
flex-grow: 1;
justify-items: stretch;
flex-wrap: nowrap;
}
#controls {
width: 100%;
}
iframe {
width: 100%;
/* 60px is element-info height plus some room */
height: calc(100% - 60px);
min-height: 500px;
}
#element-info {
height: 50px;
display: flex;
flex-flow: row wrap;
align-items: center;
width: 300px;
overflow-x: hidden;
}
#element-info .tag {
margin-right: 5px;
}
#element-info .attrs {
}
#iframe-controls {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
width: 100%;
font-size: small;
}
.pad-buttons {
display: inline-flex;
}
.buttons {
text-align: center;
}
#loader {
max-width: 400px;
border: 3px dashed gray;
margin: 15px auto;
padding: 15px;
}
.file-loader-label p {
max-width: 275px;
margin: 10px auto;
}
.file-loader-label {
padding: 5px 25px;
}
textarea {
font-size: small;
width: calc(100% - 5px);
}
#loading-webpage {
/*
position: absolute;
top: 45%;
z-index: -1;
*/
position: relative;
float: left;
z-index: -1;
height: 0;
top: -50%;
}
.status-wrapper {
padding-top: 20px;
}
.hext-controls {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
label[for="status"] {
display: flex;
flex-flow: row wrap;
align-items: center;
font-size: small;
}
label[for="status"] span {
margin-right: 5px;
}
#description p {
font-family: serif;
padding: 5px 15px 5px 0;
}
#hide {
font-family: monospace;
font-size: small;
color: #333;
cursor: pointer;
position: relative;
float: right;
margin-right: 10px;
margin-top: -20px;
}
@media screen and (max-width: 900px) {
.pane {
width: 100%;
max-width: unset;
}
}
@media screen and (max-height: 750px) {
#description .inner {
display: none;
}
}
</style>
</head>
<body>
<div class="pane-wrapper">
<div id="left" class="pane">
<div id="description">
<h1>HTML Extraction Testing Ground</h1>
<div class="inner">
<div id="hide">[x]</div>
<p>
Welcome to <a href="https://bxroberts.org/bio" target="_blank">Brandon Roberts'</a>
interactive HTML extraction tool. I'm doing experiments on
robust and <b>simple</b> methods for extracting data from HTML, with an eye
toward sites that are written to evade extraction via traditional methods like
<a href="https://developer.mozilla.org/en-US/docs/Web/XPath" target="_blank">XPath</a>
and
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors" target="_blank">CSS Selectors</a>.
</p>
<p>
This page lets you upload a pre-saved HTML webpage and use the
<a href="https://hext.thomastrapp.com/" target="_blank">Hext</a>
extraction language on it. You can paste Hext in the box
below or Hext will be generated for you by clicking on things
inside webpage you want to extract. Clicking "Extract!" will
aply the template to the webpage and highlight the extracted
data.
See <a href="" target="_blank">this blog post TK</a>
for detailed information about using Hext to simplify
extraction of data from websites.
</div>
</div>
<div id="controls">
<form id="loader">
<label for="page-file" class="file-loader-label">
<p>Load an HTML file to extract data from</p>
<div class="buttons">
<input id="page-file" type="file" accept=".html" />
</div>
</label>
</form>
<label for="hext">
<pre id="hext"># Enter Hext template here...
# You can build one automatically by clicking on text you want to extract.
# Here's an example extractor that will extract the link URL and text of all links on a page that contain a href attribute and whose text isn't blank
<a href @text=~/.+/ href:link @text:name /></pre>
</label>
<br/>
<pre id="json" readonly>// JSON extracted from the webpage will appear here</pre>
<br/>
<div class="hext-controls">
<button id="run-hext">Extract!</button>
</div>
<div class="status-wrapper">
<label for="status"><span>Status:</span>
<textarea id="status" rows="1" disabled readonly>Loading...</textarea>
</label>
</div>
</div>
<div id="output">
</div>
</div>
<div id="right" class="pane">
<iframe srcdoc="<!doctype html><html><head><style>html { font-family: sans-serif; background-color: white; }</style></head><body><p>Upload a HTML file using the file selector input.<br/>You can use a browser extension like <a href='https://github.com/gildas-lormeau/SingleFile#install' target='_blank'>SingleFile</a> to turn a webpage into a single HTML file.</p></body></html>"></iframe>
<p id="loading-webpage">Loading ...</p>
<div id="iframe-controls">
<div>
<button id="clear-hext">Clear Selected</button>
<button id="clear-results">Clear Results</button>
</div>
<div id="element-info">
<span class="tag"></span>
<span class="attrs"></span>
</div>
<div>
Element Padding: <span id="current-padding">1</span>
<div class="pad-buttons">
<button id="inc-padding">+</button>
<button id="dec-padding">-</button>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="src/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="hextractor.js" type="module"></script>
</html>