Pythonista icon indicating copy to clipboard operation
Pythonista copied to clipboard

Got scraper working

Open Kamik423 opened this issue 6 years ago • 1 comments

No time to make a separate pull request for this, but I got the scraper working:

import ui
import time

class Scraper (object):
    def __init__(self, url, js = 'document.documentElement.outerHTML'):
        self.wv = ui.WebView()
        self.wv.delegate = self
        self.wv.load_url(url)
        self.js = js
        self.response = None
    
    def webview_did_finish_load(self, webview):
        self.response = webview.eval_js(self.js)
    
    @property
    def value(self):
        while self.response is None:
            time.sleep(0.1)
        return self.response

def main():
    v = Scraper(url, 'document.documentElement.outerHTML;').value

It is a bit of a hack and probably not all that efficient, but it works perfectly

Kamik423 avatar Jan 04 '19 09:01 Kamik423

Hi, thanks I will check and update the script. Sometimes it takes time to answer and merge pull requests but thanks for keeping the repo up to date.

tdamdouni avatar Mar 17 '20 22:03 tdamdouni