spider 2.51.49

A web crawler and scraper, building blocks for data curation workloads.
Documentation
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
//! JavaScript tests — Chrome/Smart mode only.
//! These pages require JS execution to render their content.

use crate::helpers::*;

// --- Chrome-mode tests ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn dynamically_inserted_text() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/dynamically-inserted-text").await {
        let html = page.get_html();
        assert!(
            html.len() > 100,
            "chrome should render dynamically inserted text"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn dynamically_inserted_text_meta_data() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/dynamically-inserted-text-meta-data").await {
        assert!(
            !page.get_html().is_empty(),
            "chrome should render dynamically inserted meta data"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn ajax_return_data() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/ajax-return-data").await {
        let html = page.get_html();
        assert!(html.len() > 100, "chrome should wait for AJAX data");
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn onload_added_title() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/onload-added-title").await {
        let html = page.get_html();
        let title = extract_title(&html);
        assert!(
            title.is_some() && !title.as_ref().unwrap().is_empty(),
            "chrome should see dynamically added title"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn onload_inserted_canonical() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/onload-inserted-canonical").await {
        let html = page.get_html();
        let canonical = extract_canonical(&html);
        assert!(
            canonical.is_some(),
            "chrome should see dynamically inserted canonical"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn dynamically_inserted_nofollow() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/dynamically-inserted-nofollow").await {
        let html = page.get_html().to_lowercase();
        assert!(
            html.contains("nofollow") || html.contains("rel="),
            "chrome should see dynamically inserted nofollow"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

// --- Renderer timeouts ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn renderer_timeout_1() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/renderer_timeout/1"),
    )
    .await;
    assert!(result.is_ok(), "renderer_timeout/1 should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn renderer_timeout_2() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/renderer_timeout/2"),
    )
    .await;
    assert!(result.is_ok(), "renderer_timeout/2 should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn renderer_timeout_3() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/renderer_timeout/3"),
    )
    .await;
    assert!(result.is_ok(), "renderer_timeout/3 should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn renderer_timeout_4() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/renderer_timeout/4"),
    )
    .await;
    assert!(result.is_ok(), "renderer_timeout/4 should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn renderer_timeout_5() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/renderer_timeout/5"),
    )
    .await;
    assert!(result.is_ok(), "renderer_timeout/5 should complete");
}

// --- Window location redirects ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_redirect_internal() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/window-location-internal"),
    )
    .await;
    assert!(result.is_ok(), "JS redirect should complete in chrome");
    if let Some(page) = result.unwrap() {
        assert!(
            !page.get_html().is_empty(),
            "JS redirect should produce content"
        );
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_redirect_external() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/window-location-external"),
    )
    .await;
    assert!(result.is_ok(), "external JS redirect should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_function_absolute() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/window-location-function-absolute"),
    )
    .await;
    assert!(result.is_ok(), "absolute JS redirect should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_function_relative() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/window-location-function-relative"),
    )
    .await;
    assert!(result.is_ok(), "relative JS redirect should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_onchange() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/window-location-onchange"),
    )
    .await;
    assert!(result.is_ok(), "onchange JS redirect should complete");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_location_onclick() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/window-location-onclick").await {
        assert!(
            !page.get_html().is_empty(),
            "onclick page should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn window_open() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/window-open").await {
        assert!(
            !page.get_html().is_empty(),
            "window-open should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

// --- JS link discovery ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn onmousedown() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/onmousedown").await {
        assert!(
            !page.get_html().is_empty(),
            "onmousedown should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn concatenatedlink() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/concatenatedlink").await {
        assert!(
            !page.get_html().is_empty(),
            "concatenatedlink should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn data_hreflink() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/data-hreflink").await {
        assert!(
            !page.get_html().is_empty(),
            "data-hreflink should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn push_state() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/push_state").await {
        assert!(
            !page.get_html().is_empty(),
            "push_state should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn onclick_reveals_element() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) =
        fetch_page_chrome("/javascript/onclick-reveals-element-programmatically-added-onclick")
            .await
    {
        assert!(
            !page.get_html().is_empty(),
            "onclick-reveals should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

// --- Dialogs ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn dialog_window() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/dialog_window"),
    )
    .await;
    assert!(result.is_ok(), "dialog_window should not hang");
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn alert_box() {
    if !run_live_tests() {
        return;
    }

    let result = spider::tokio::time::timeout(
        std::time::Duration::from_secs(30),
        fetch_page_chrome("/javascript/alert_box"),
    )
    .await;
    assert!(result.is_ok(), "alert_box should not hang");
}

// --- Script blocking ---

#[cfg(feature = "chrome")]
#[tokio::test]
async fn ad_script() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/ad_script").await {
        assert!(!page.get_html().is_empty(), "ad_script should have content");
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

#[cfg(feature = "chrome")]
#[tokio::test]
async fn analytics_script() {
    if !run_live_tests() {
        return;
    }

    if let Some(page) = fetch_page_chrome("/javascript/analytics_script").await {
        assert!(
            !page.get_html().is_empty(),
            "analytics_script should have content"
        );
    } else {
        eprintln!("SKIP: chrome not available");
    }
}

// --- HTTP-only test: JS pages should have script tags without a browser ---

#[tokio::test]
async fn js_page_http_has_script_tags() {
    if !run_live_tests() {
        return;
    }

    let page = fetch_page_http("/javascript/dynamically-inserted-text").await;
    let html = page.get_html().to_lowercase();
    assert!(
        html.contains("<script"),
        "HTTP fetch of JS page should see raw script tags"
    );
}

// --- Smart mode tests ---

#[cfg(feature = "smart")]
#[tokio::test]
async fn dynamically_inserted_text_smart() {
    if !run_live_tests() {
        return;
    }

    let pages = crawl_collect_smart("/javascript/dynamically-inserted-text", 1, 0).await;
    assert!(!pages.is_empty(), "smart mode should fetch JS page");
    let html = pages[0].get_html();
    assert!(html.len() > 100, "smart mode should render JS content");
}

#[cfg(feature = "smart")]
#[tokio::test]
async fn ajax_return_data_smart() {
    if !run_live_tests() {
        return;
    }

    let pages = crawl_collect_smart("/javascript/ajax-return-data", 1, 0).await;
    assert!(!pages.is_empty(), "smart mode should fetch AJAX page");
}