|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- encoding: utf-8 -*- |
|
3
|
|
|
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: |
|
4
|
|
|
# Author: Binux<[email protected]> |
|
5
|
|
|
# http://binux.me |
|
6
|
|
|
# Created on 2015-01-24 13:44:10 |
|
7
|
|
|
|
|
8
|
|
|
from httpbin import app |
|
9
|
|
|
|
|
10
|
|
|
@app.route('/pyspider/test.html') |
|
11
|
|
|
def test_page(): |
|
12
|
|
|
return ''' |
|
13
|
|
|
<a href="/404">404 |
|
14
|
|
|
<a href="/links/10/0">0 |
|
15
|
|
|
<a href="/links/10/1">1 |
|
16
|
|
|
<a href="/links/10/2">2 |
|
17
|
|
|
<a href="/links/10/3">3 |
|
18
|
|
|
<a href="/links/10/4">4 |
|
19
|
|
|
<a href="/gzip">gzip |
|
20
|
|
|
<a href="/get">get |
|
21
|
|
|
<a href="/deflate">deflate |
|
22
|
|
|
<a href="/html">html |
|
23
|
|
|
<a href="/xml">xml |
|
24
|
|
|
<a href="/robots.txt">robots |
|
25
|
|
|
<a href="/cache">cache |
|
26
|
|
|
<a href="/stream/20">stream |
|
27
|
|
|
''' |
|
28
|
|
|
|
|
29
|
|
|
@app.route('/pyspider/ajax.html') |
|
30
|
|
|
def test_ajax(): |
|
31
|
|
|
return ''' |
|
32
|
|
|
<div class=status>loading...</div> |
|
33
|
|
|
<div class=ua></div> |
|
34
|
|
|
<div class=ip></div> |
|
35
|
|
|
<script> |
|
36
|
|
|
var xhr = new XMLHttpRequest(); |
|
37
|
|
|
xhr.onload = function() { |
|
38
|
|
|
var data = JSON.parse(xhr.responseText); |
|
39
|
|
|
document.querySelector('.status').innerHTML = 'done'; |
|
40
|
|
|
document.querySelector('.ua').innerHTML = data.headers['User-Agent']; |
|
41
|
|
|
document.querySelector('.ip').innerHTML = data.origin; |
|
42
|
|
|
} |
|
43
|
|
|
xhr.open("get", "/get", true); |
|
44
|
|
|
xhr.send(); |
|
45
|
|
|
</script> |
|
46
|
|
|
''' |
|
47
|
|
|
|
|
48
|
|
|
@app.route('/pyspider/ajax_click.html') |
|
49
|
|
|
def test_ajax_click(): |
|
50
|
|
|
return ''' |
|
51
|
|
|
<div class=status>loading...</div> |
|
52
|
|
|
<div class=ua></div> |
|
53
|
|
|
<div class=ip></div> |
|
54
|
|
|
<a href="javascript:void(0)" onclick="load()">load</a> |
|
55
|
|
|
<script> |
|
56
|
|
|
function load() { |
|
57
|
|
|
var xhr = new XMLHttpRequest(); |
|
58
|
|
|
xhr.onload = function() { |
|
59
|
|
|
var data = JSON.parse(xhr.responseText); |
|
60
|
|
|
document.querySelector('.status').innerHTML = 'done'; |
|
61
|
|
|
document.querySelector('.ua').innerHTML = data.headers['User-Agent']; |
|
62
|
|
|
document.querySelector('.ip').innerHTML = data.origin; |
|
63
|
|
|
} |
|
64
|
|
|
xhr.open("get", "/get", true); |
|
65
|
|
|
xhr.send(); |
|
66
|
|
|
} |
|
67
|
|
|
</script> |
|
68
|
|
|
''' |
|
69
|
|
|
|