omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to render a web background and save the whole page image to local?

    Pythonista
    2
    3
    1634
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • louxingliang
      louxingliang last edited by

      I want to write a python script to replace me screenshot a web. I just need to input the website such as "www.google.com", then the script will save the whole page to local. How to realize it ?

      I made a simple test script, but it seems don't work...

      from ui import WebView, ImageContext
      
      w=WebView()
      w.load_url('http://www.baidu.com')
      
      with ImageContext(w.width,w.hight) as ctx:
          w.draw_snapshot()
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @louxingliang last edited by cvp

        @louxingliang try this. Snap button enable when web page loaded. Image saved as snap.jpg in same folder as your script

        import ui
        import io
        from PIL import Image
        
        v = ui.WebView()
        b = ui.ButtonItem()
        class MyWebViewDelegate ():
        	def webview_did_finish_load(self, webview):
        		b.enabled = True
        v.delegate = MyWebViewDelegate()
        def snap(sender):
        	# create image with infos TextView 
        	with ui.ImageContext(v.width, v.height) as ctx:
        		v.draw_snapshot()
        		pil = Image.open(io.BytesIO(ctx.get_image().to_png())) # ui.image -> pil
        	pil.save('snap.jpg', quality=95)
        b.title = 'snap'
        b.enabled = False
        b.action = snap
        v.right_button_items = (b,)
        v.present()
        v.load_url('http://www.baidu.com')
        
        1 Reply Last reply Reply Quote 1
        • louxingliang
          louxingliang last edited by

          Thanks! This script works quite well!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors