coding utf8 from WebDAV import client import urlparse import sys from

 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
# -*- coding: utf8 -*-
from WebDAV import client
import urlparse
import sys
from urllib import unquote
from BeautifulSoup import *
class Huita:
def __init__(self, link):
self.link = link
self.links = []
self.chain(link)
def get_links(self, xml):
soup = BeautifulSoup(xml)
for record in soup('a:href'):
link = unquote(record.renderContents())
if link not in self.links:
self.links.append(link)
self.chain(link)
print link
def chain(self, link):
res = client.Resource(link)
response = res.propfind(url=link, depth=1)
self.get_links(response.get_body())
def result(self):
print self.links
_url = sys.argv[1:2]
if not _url:
sys.stderr.write("""usage: %s url
where url refers to a WebDAV enabled location.
""" % sys.argv[0])
sys.exit(1)
#
_t = urlparse.urlparse(_url[0])
SCHEME=_t[0].lower()
SERVER=_t[1]
TEST_URL = _url[0]
response = Huita(TEST_URL)
print response.result()