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.


    Get HTML from UI.webview

    Pythonista
    2
    3
    2338
    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.
    • cook
      cook last edited by

      Is it possible to get the HTML from a loaded url in UI.Webview?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        maybe by using eval_js ('document.documentElement.outerHTML'), but i have not tried this.

        1 Reply Last reply Reply Quote 0
        • cook
          cook last edited by

          Thanks @JonB!
          It does work- but needs some other stuff.

          Either there should be a delay before doing eval_js, or what I found to be better was using re module to check for certain html code. JavaScript onLoad should apparently work but wasn't.

          It isn't required to present the UI.view in order to do this, so what we have here is a very simple way in Pythonista to scrape a page that has generated content. I know it's possible with various headless browser modules- but the WebKit is already in UI.webview

          Here's what I have that works:
          <pre><code>
          import ui
          import console
          import re
          console.clear()

          webb = ui.WebView()
          webb.load_url('your URL ')
          js = 'document.documentElement.outerHTML'

          reg = '' #some text to find to determine if page or script has been loaded/evaluated

          while True:
          html = webb.eval_js(js)
          if re.findall(reg, html):
          print html
          break
          else:
          pass

          </code></pre>

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