How to use the wayback.waybacklapse.closing function in wayback

To help you get started, we’ve selected a few wayback examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kpurdon / waybacklapse / wayback / waybacklapse.py View on Github external
def capture_url(item, width, height, allow_redirects):

    output_fn = os.path.join(TMP_OUTPUT_DIR, '{0}.png'.format(item[0]))
    print('Attemting to capture: {0}'.format(item[1]))

    with closing(webdriver.PhantomJS()) as driver:
        driver.set_window_size(width, height)
        driver.get(item[1])
        try:
            redirect_link = driver.find_element_by_link_text('Impatient?')
            redirected = True  # redirect was found (redirect if allowed)
            if allow_redirects:
                while True:  # continue until all redirects are resolved
                    print('Redirected to: {0}'.format(redirect_link.get_attribute('href')))
                    redirect_link.click()
        except NoSuchElementException:
            redirected = False  # no redirect was found
        except StaleElementReferenceException:
            redirected = True  # redirect resolved before the "impatient" link was clicked
        finally:
            if not redirected or allow_redirects:  # only capture redirect if redirects are allowed
                driver.get_screenshot_as_file(output_fn)

wayback

Python API to Internet Archive Wayback Machine

BSD-3-Clause
Latest version published 6 months ago

Package Health Score

69 / 100
Full package analysis