Closed robintw closed 2 years ago
It's not really designed as a Python library at the moment, so if you import functions from it directly I can't guarantee your code won't break with future updates to shot-scraper
.
You could try using the take_shot()
function directly, but I instead recommend using the Click CLIRunner
mechanism - something like this:
from click.testing import CliRunner
from shot_scraper import cli
runner = CliRunner()
result = runner.invoke(cli.cli, ["shot", "https://www.example.com/"])
Since this is itself calling the CLI interface defied for the tool, this won't break with future updates to shot-scraper
(at least as long as those updates don't represent a breaking change to the CLI interface - and I plan not to make changes that break that).
there is nothing output
from click.testing import CliRunner
from shot_scraper import cli
runner = CliRunner()
result = runner.invoke(cli.cli, ["shot", "https://www.baidu.com/"])
from click.testing import CliRunner
from shot_scraper import cli
print('---')
runner = CliRunner()
result = runner.invoke(cli.cli, ["shot","www.baidu.com"])
result = runner.invoke(cli.cli, ["shot","www.baidu.com","--width 412", "--height 915"])
result = runner.invoke(cli.cli, ["shot","www.baidu.com --width 412 --height 915"])
result = runner.invoke(cli.cli, ["shot", "pdf","www.baidu.com"])
result = runner.invoke(cli.cli, ["shot", "pdf www.baidu.com"])
only the first works @simonw
I've just started using shot-scraper, and have been really impressed - thank you for creating it.
I want to programmatically set some of the command-line arguments, and rather than running it from Python using subprocess, I thought I'd try and run it directly from Python, as shot-scraper is written in Python itself.
I found the promising looking
shot
function in thecli
module - but no matter how I call it, I get an error saying that the arguments aren't valid, or raising an AssertionError or similar. Is it not possible to manually call a function that has been decorated with click decorators like this? Is there any other way to call this from Python without re-implementing most of theshot
function in my own code?