snapper.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Snapper 作者: dxa4481 项目源码 文件源码
def host_worker(hostQueue, fileQueue, timeout, user_agent, verbose):
    dcap = dict(DesiredCapabilities.PHANTOMJS)
    dcap["phantomjs.page.settings.userAgent"] = user_agent
    dcap["accept_untrusted_certs"] = True
    driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'], desired_capabilities=dcap) # or add to your PATH
    driver.set_window_size(1024, 768) # optional
    driver.set_page_load_timeout(timeout)
    while(not hostQueue.empty()):
        host = hostQueue.get()
        if not host.startswith("http://") and not host.startswith("https://"):
            host1 = "http://" + host
            host2 = "https://" + host
            filename1 = os.path.join("output", "images", str(uuid4()) + ".png")
            filename2 = os.path.join("output", "images", str(uuid4()) + ".png")
            if verbose:
                print("Fetching %s" % host1)
            if host_reachable(host1, timeout) and save_image(host1, filename1, driver):
                fileQueue.put({host1: filename1})
            else:
                if verbose:
                    print("%s is unreachable or timed out" % host1)
            if verbose:
                print("Fetching %s" % host2)
            if host_reachable(host2, timeout) and save_image(host2, filename2, driver):
                fileQueue.put({host2: filename2})
            else:
                if verbose:
                    print("%s is unreachable or timed out" % host2)
        else:
            filename = os.path.join("output", "images", str(uuid4()) + ".png")
            if verbose:
                print("Fetching %s" % host)
            if host_reachable(host, timeout) and save_image(host, filename, driver):
                fileQueue.put({host: filename})
            else:
                if verbose:
                    print("%s is unreachable or timed out" % host)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号