Beispiel #1
0
    def __main_qt():
        # Render the page.
        # If this method times out or loading failed, a
        # RuntimeException is thrown
        try:
            # Initialize WebkitRenderer object
            renderer = WebkitRenderer()
            renderer.logger = logger
            renderer.width = options.geometry[0]
            renderer.height = options.geometry[1]
            renderer.timeout = options.timeout
            renderer.wait = options.wait
            renderer.format = options.format
            renderer.grabWholeWindow = options.window
            renderer.renderTransparentBackground = options.transparent
            renderer.encodedUrl = options.encoded_url

            if options.scale:
                renderer.scaleRatio = options.ratio
                renderer.scaleToWidth = options.scale[0]
                renderer.scaleToHeight = options.scale[1]

            if options.features:
                if "javascript" in options.features:
                    renderer.qWebSettings[QWebSettings.JavascriptEnabled] = True
                if "plugins" in options.features:
                    renderer.qWebSettings[QWebSettings.PluginsEnabled] = True

            renderer.render_to_file(url=options.url, file_object=options.output)
            options.output.close()
            QApplication.exit(0)
        except RuntimeError, e:
            logger.error("main: %s" % e)
            print >> sys.stderr, e
            QApplication.exit(1)
Beispiel #2
0
def renderer_func():   
    renderer = WebkitRenderer()
    renderer.width = 800
    renderer.height = 600
    renderer.timeout = 10
    renderer.wait = 1
    renderer.format = "png"
    renderer.grabWholeWindow = False

    outfile = open("stackoverflow.png", "w")
    renderer.render_to_file(url="http://stackoverflow.com", file=outfile)
    outfile.close()
def generate_thumbnail(url, width, height):
	renderer = WebkitRenderer()
	renderer.width = 1280
	renderer.height = 768
	renderer.timeout = 60
	renderer.wait = 3
	renderer.format = "png"
	renderer.scaleRatio = "crop"
	renderer.scaleToWidth = width
	renderer.scaleToHeight = height
	renderer.grabWholeWindow = False
	#outfile = open("stackoverflow.png", "w")
	#renderer.render_to_file(url=url, file=outfile)
	#outfile.close()
	return renderer.render_to_bytes(url)
    def __main_qt():
        # Render the page.
        # If this method times out or loading failed, a
        # RuntimeException is thrown
        try:
            # Initialize WebkitRenderer object
            renderer = WebkitRenderer()
            renderer.logger = logger
            renderer.width = options.geometry[0]
            renderer.height = options.geometry[1]
            renderer.timeout = options.timeout
            renderer.wait = options.wait
            renderer.format = options.format
            renderer.grabWholeWindow = options.window
            renderer.renderTransparentBackground = options.transparent
            renderer.encodedUrl = options.encoded_url
            if options.cookies:
                renderer.cookies = options.cookies

            if options.scale:
                renderer.scaleRatio = options.ratio
                renderer.scaleToWidth = options.scale[0]
                renderer.scaleToHeight = options.scale[1]

            if options.features:
                if "javascript" in options.features:
                    renderer.qWebSettings[QWebSettings.JavascriptEnabled] = True
                if "plugins" in options.features:
                    renderer.qWebSettings[QWebSettings.PluginsEnabled] = True

            for f in options.urls:
                read = 'file://' + os.path.join(options.input_dir, f) if options.input_dir else f

                save = os.path.join(options.output_dir, f) if options.output_dir else f
                save = os.path.splitext(save)[0] if not options.keep_ext else save
                save = save + '.' + options.format

                if not os.path.isdir(os.path.dirname(save)):
                    os.makedirs(os.path.dirname(save))

                with open(save, "w") as save_file:
                    renderer.render_to_file(res=read, file_object=save_file)

            QApplication.exit(0)
        except RuntimeError, e:
            logger.error("main: %s" % e)
            print >> sys.stderr, e
            QApplication.exit(1)
Beispiel #5
0
    def __main_qt():
        # Render the page.
        # If this method times out or loading failed, a
        # RuntimeException is thrown
        try:
            # Initialize WebkitRenderer object
            renderer = WebkitRenderer()
            renderer.logger = logger
            renderer.width = 400
            renderer.height = 600
            renderer.timeout = 5
            renderer.wait = 1
            renderer.format = options.format
            renderer.grabWholeWindow = options.window
            renderer.renderTransparentBackground = options.transparent
            renderer.encodedUrl = options.encoded_url
            if options.cookies:
                renderer.cookies = options.cookies

            if options.scale:
                renderer.scaleRatio = options.ratio
                renderer.scaleToWidth = options.scale[0]
                renderer.scaleToHeight = options.scale[1]

            if options.features:
                if "javascript" in options.features:
                    renderer.qWebSettings[
                        QWebSettings.JavascriptEnabled] = True
                if "plugins" in options.features:
                    renderer.qWebSettings[QWebSettings.PluginsEnabled] = True

            print(options.url)
            renderer.render_to_file(res=options.url,
                                    file_object=options.output)
            options.output.close()
            QApplication.exit(0)
        except RuntimeError as e:
            logger.error("main: %s" % e)
            print(e)
            QApplication.exit(1)
    def __main_qt():
        # Render the page.
        # If this method times out or loading failed, a
        # RuntimeException is thrown
        try:
            # Initialize WebkitRenderer object
            renderer = WebkitRenderer()
            renderer.logger = logger
            renderer.width = options.geometry[0]
            renderer.height = options.geometry[1]
            renderer.timeout = options.timeout
            renderer.wait = options.wait
            renderer.format = options.format
            renderer.grabWholeWindow = options.window
            renderer.renderTransparentBackground = options.transparent
            renderer.quality = options.quality

            if options.scale:
                renderer.scaleRatio = options.ratio
                renderer.scaleToWidth = options.scale[0]
                renderer.scaleToHeight = options.scale[1]

            if options.features:
                if "javascript" in options.features:
                    renderer.qWebSettings[QWebSettings.JavascriptEnabled] = True
                if "plugins" in options.features:
                    renderer.qWebSettings[QWebSettings.PluginsEnabled] = True

            try:
                res = 0
                renderer.render_to_file(
                    url=options.url,
                    file_object=options.output
                )
            except BaseWebkitException, e:
                res = e.status_code
            finally:
                options.output.close()
                QApplication.exit(res)
Beispiel #7
0
    def __main_qt():
        # Render the page.
        # If this method times out or loading failed, a
        # RuntimeException is thrown
        try:
            # Initialize WebkitRenderer object
            renderer = WebkitRenderer()
            renderer.logger = logger
            renderer.width = options.geometry[0]
            renderer.height = options.geometry[1]
            renderer.timeout = options.timeout
            renderer.wait = options.wait
            renderer.format = options.format
            renderer.grabWholeWindow = options.window
            renderer.renderTransparentBackground = options.transparent
            renderer.quality = options.quality

            if options.scale:
                renderer.scaleRatio = options.ratio
                renderer.scaleToWidth = options.scale[0]
                renderer.scaleToHeight = options.scale[1]

            if options.features:
                if "javascript" in options.features:
                    renderer.qWebSettings[
                        QWebSettings.JavascriptEnabled] = True
                if "plugins" in options.features:
                    renderer.qWebSettings[QWebSettings.PluginsEnabled] = True

            try:
                res = 0
                renderer.render_to_file(url=options.url,
                                        file_object=options.output)
            except BaseWebkitException, e:
                res = e.status_code
            finally:
                options.output.close()
                QApplication.exit(res)