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.
|
||||
|
||||
Usage:
|
||||
playfox https://twitter.com
|
||||
playfox -P jtm https://private.site
|
||||
playfox --interactive https://site.com
|
||||
playfox URL # load page, print title
|
||||
playfox --dump URL # print rendered html
|
||||
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 sys
|
||||
|
|
@ -50,6 +53,8 @@ def main():
|
|||
url = None
|
||||
dump = False
|
||||
interactive = False
|
||||
wait_for = None
|
||||
quiet = False
|
||||
|
||||
i = 0
|
||||
while i < len(args):
|
||||
|
|
@ -62,6 +67,12 @@ def main():
|
|||
elif args[i] == "--interactive" or args[i] == "-i":
|
||||
interactive = True
|
||||
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"):
|
||||
url = args[i]
|
||||
i += 1
|
||||
|
|
@ -69,7 +80,7 @@ def main():
|
|||
i += 1
|
||||
|
||||
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)
|
||||
|
||||
# get cookies
|
||||
|
|
@ -83,12 +94,23 @@ def main():
|
|||
|
||||
page = context.new_page()
|
||||
|
||||
# logging
|
||||
page.on("console", lambda msg: print(f"[console] {msg.text}"))
|
||||
page.on("pageerror", lambda err: print(f"[error] {err}"))
|
||||
page.on("request", lambda req: print(f"[req] {req.method} {req.url}"))
|
||||
# logging (unless quiet)
|
||||
if not quiet:
|
||||
page.on("console", lambda msg: print(f"[console] {msg.text}", file=sys.stderr))
|
||||
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:
|
||||
print(page.content())
|
||||
|
|
|
|||
Loading…
Reference in a new issue