本文整理汇总了Python中ghost.Ghost.hide方法的典型用法代码示例。如果您正苦于以下问题:Python Ghost.hide方法的具体用法?Python Ghost.hide怎么用?Python Ghost.hide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ghost.Ghost
的用法示例。
在下文中一共展示了Ghost.hide方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import hide [as 别名]
#.........这里部分代码省略.........
self.ghost.load_cookies(cookie_file)
except IOError:
self.display("cookie: IOError", '<font color=red>$</font>', 'url')
self.max_depth = 0
self.url_queue = []
self.location = location.split('?')[0]
# dvwa_security(self.__ghost, 'low')
def go(self):
self.display("...crawling", "<b>$<b>", 'url')
times = 0
while True:
try:
self.ghost.open(self.location)
current_url, resources = self.ghost.evaluate('window.location.href') # redirect
self.location = str(current_url)
r = urlparse.urlparse(self.location)
self.host = r.netloc # slash(r.scheme + "://" + r.netloc)
self.display(self.location, "<a href='$'>$<a>", 'url')
self.url_queue.append(self.location)
break
except TimeoutError:
times = times + 1
if times == 5:
self.display("TimeoutError", '<font color=red>$</font>', 'url')
self.exit()
self.crawler_page(self.location, 0) # url, depth
# Test
for url in self.url_queue:
t = Test(self.ghost, url, self.mainwindow)
t.test()
self.exit()
def crawler_page(self, location, depth):
if depth >= self.max_depth:
return
try:
self.ghost.open(location)
current_url, resources = self.ghost.evaluate('window.location.href') # redirect
location = str(current_url)
except TimeoutError:
return
urls = []
soup = BeautifulSoup(str(self.ghost.content), from_encoding='utf-8')
bs_as = soup.find_all('a')
for a in bs_as:
url = self.convert_a(location, a)
if url:
r = urlparse.urlparse(url)
host = r.netloc # slash(r.scheme + "://" + r.netloc)
if host == self.host and url not in self.url_queue:
self.display(url, "<a href='$'>$<a>", 'url')
self.url_queue.append(url)
urls.append(url)
for url in urls:
self.crawler_page(url, depth + 1)
def display(self, content, format=None, widget=None):
print content
if self.mainwindow:
self.mainwindow.display(content, format, widget)
def convert_a(self, location, a):
if str(type(a)) == "<class 'bs4.element.Tag'>":
try:
href = a['href']
except KeyError:
return None
elif str(type(a)) == "<type 'str'>":
href = a
else:
return None # <type 'unicode'>
href = href.strip()
# useless
if href.lower() in ['javascript:;', "javacript:void(0);", "javascript:void(0)", "javascript:void(0);",
'return false;', '/', "http://www", ""]:
return None
for s in ['mailto:', '#', 'javascript:']:
if href.lower().startswith(s):
return None
# normal
if href.startswith('http://') or href.startswith('https://'):
return href
# path
if href.startswith("//"):
href = "http:" + href # //www.baidu.com/s
elif href.startswith("/"):
href = self.host + href[1:]
else:
href = slash(location) + href
return href
def exit(self):
self.ghost.hide()
if self.mainwindow:
self.mainwindow.go_button.setEnabled(True)
self.mainwindow.finish()
else:
print "Finish"
self.ghost.sleep(120)