diff --git a/README.md b/README.md index e92564d..ce62184 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,16 @@ way of knowing when that script has finished doing its work. For this reason, the external script should execute at the end ```console.log("__PHANTOM_PY_DONE__");``` when done. This will trigger the PDF generation or the file saving, after which phantompy will exit. +If you do not want to run any javascipt file, this trigger is provided +in the code by default. It is important to remember that since you're just running WebKit, you can use everything that WebKit supports, including the usual JS client libraries, CSS, CSS @media types, etc. +Qt picks up proxies from the environment, so this will respect +```https_proxy``` or ```http_proxy``` if set. + ## Dependencies * Python3 @@ -73,9 +78,11 @@ The standalone program is ```quash_phantompy.py``` ### Arguments ``` - Can be a http(s) URL or a path to a local file - Path and name of PDF file to generate -[] (optional) Path and name of a JavaScript file to execute +--js_input (optional) Path and name of a JavaScript file to execute on the HTML +--html_output (optional) Path a HTML output file to generate after JS is applied +--pdf_output (optional) Path and name of PDF file to generate after JS is applied +--log_level 10=debug 20=info 30=warn 40=error +html_or_url - required argument, a http(s) URL or a path to a local file. ``` Setting ```DEBUG=1``` in the environment will give debugging messages on ```stderr```. diff --git a/lookupdns.py b/lookupdns.py new file mode 100644 index 0000000..e792aec --- /dev/null +++ b/lookupdns.py @@ -0,0 +1,79 @@ +#!/usr/local/bin/python3.sh +# -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* + +# Looks for urls https://dns.google/resolve? +# and parses them to extract a magic field. +# https://dns.google/resolve?name=domain.name&type=TXT&cd=true&do=true + +import sys +import os + +from phantompy import Render + +global LOG +import logging +import warnings +warnings.filterwarnings('ignore') +LOG = logging.getLogger() + +class LookFor(Render): + + def __init__(self, app, do_print=True, do_save=False): + app.lfps = [] + self._app = app + self.do_print = do_print + self.do_save = do_save + self.progress = 0 + self.we_run_this_tor_relay = None + Render.__init__(self, app, do_print, do_save) + + def _exit(self, val): + Render._exit(self, val) + self.percent = 100 + LOG.debug(f"phantom.py: Exiting with val {val}") + i = self.uri.find('name=') + fp = self.uri[i+5:] + i = fp.find('.') + fp = fp[:i] + # threadsafe? + self._app.lfps.append(fp) + + def _html_callback(self, *args): + """print(self, QPrinter, Callable[[bool], None])""" + if type(args[0]) is str: + self._save(args[0]) + i = self.ilookfor(args[0]) + self._onConsoleMessage(i, "__PHANTOM_PY_SAVED__", 0 , '') + + def ilookfor(self, html): + import json + marker = '
'
+      if marker not in html: return -1
+      i = html.find(marker) + len(marker)
+      html = html[i:]
+      assert html[0] == '{', html
+      i = html.find('