Get playfire working
This commit is contained in:
parent
ae104baa3a
commit
8e34b09c53
1 changed files with 31 additions and 9 deletions
40
playfox
40
playfox
|
|
@ -6,9 +6,12 @@
|
||||||
Headless Firefox with your cookies via cookiefire.
|
Headless Firefox with your cookies via cookiefire.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
playfox https://twitter.com
|
playfox URL # load page, print title
|
||||||
playfox -P jtm https://private.site
|
playfox --dump URL # print rendered html
|
||||||
playfox --interactive https://site.com
|
playfox -i URL # interactive python repl
|
||||||
|
playfox -w 'selector' URL # wait for selector before proceeding
|
||||||
|
playfox -q URL # quiet (no request logging)
|
||||||
|
playfox -P profile URL # use specific firefox profile
|
||||||
"""
|
"""
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -50,6 +53,8 @@ def main():
|
||||||
url = None
|
url = None
|
||||||
dump = False
|
dump = False
|
||||||
interactive = False
|
interactive = False
|
||||||
|
wait_for = None
|
||||||
|
quiet = False
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(args):
|
while i < len(args):
|
||||||
|
|
@ -62,6 +67,12 @@ def main():
|
||||||
elif args[i] == "--interactive" or args[i] == "-i":
|
elif args[i] == "--interactive" or args[i] == "-i":
|
||||||
interactive = True
|
interactive = True
|
||||||
i += 1
|
i += 1
|
||||||
|
elif args[i] == "-w" and i + 1 < len(args):
|
||||||
|
wait_for = args[i + 1]
|
||||||
|
i += 2
|
||||||
|
elif args[i] == "-q" or args[i] == "--quiet":
|
||||||
|
quiet = True
|
||||||
|
i += 1
|
||||||
elif args[i].startswith("http"):
|
elif args[i].startswith("http"):
|
||||||
url = args[i]
|
url = args[i]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
@ -69,7 +80,7 @@ def main():
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if not url:
|
if not url:
|
||||||
print("Usage: playfox [-P profile] [--dump] [--interactive] URL", file=sys.stderr)
|
print("Usage: playfox [-P profile] [--dump] [-i] [-w selector] [-q] URL", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# get cookies
|
# get cookies
|
||||||
|
|
@ -83,12 +94,23 @@ def main():
|
||||||
|
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
|
|
||||||
# logging
|
# logging (unless quiet)
|
||||||
page.on("console", lambda msg: print(f"[console] {msg.text}"))
|
if not quiet:
|
||||||
page.on("pageerror", lambda err: print(f"[error] {err}"))
|
page.on("console", lambda msg: print(f"[console] {msg.text}", file=sys.stderr))
|
||||||
page.on("request", lambda req: print(f"[req] {req.method} {req.url}"))
|
page.on("pageerror", lambda err: print(f"[error] {err}", file=sys.stderr))
|
||||||
|
page.on("request", lambda req: print(f"[req] {req.method} {req.url}", file=sys.stderr))
|
||||||
|
|
||||||
page.goto(url)
|
page.goto(url, wait_until="domcontentloaded")
|
||||||
|
|
||||||
|
# wait for specific selector if requested
|
||||||
|
if wait_for:
|
||||||
|
try:
|
||||||
|
page.wait_for_selector(wait_for, timeout=15000, state="attached")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[warn] wait_for '{wait_for}' timed out: {e}", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
# default: wait a bit for SPAs/turbo to settle
|
||||||
|
page.wait_for_timeout(2000)
|
||||||
|
|
||||||
if dump:
|
if dump:
|
||||||
print(page.content())
|
print(page.content())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue