Support Multiple URLs in CLI Commands
Have you searched if there an existing feature request for this?
- [x] I have searched the existing requests
Feature description
Currently, the Scrapling CLI commands (get, fetch, and stealthy-fetch) only accept a single URL and a single output file. To scrape multiple pages, users must run the CLI command multiple times in a loop, which incurs significant overhead (such as repeatedly spinning up and tearing down the browser browser-side).
Could we add support for processing multiple URLs in a single run? Ideally, the CLI would allow:
- Multiple URLs as arguments: e.g.,
scrapling extract fetch "url1" "url2" --output-dir ./results(or automatically naming output files). - An input file containing URLs: e.g.,
scrapling extract fetch --input-file urls.txt --output-dir ./resultsto read one URL per line.
Sorry, but this feature is not planned to be added.
@zenwav you can actually do this today in one process with scrapling shell -c, it keeps a single browser alive for the whole batch:
scrapling shell -c "
from scrapling.core.shell import Convertor
with DynamicSession(headless=True) as s:
for url in open('urls.txt').read().split():
Convertor.write_content_to_file(s.fetch(url), url.split('/')[-1] + '.md')
"
and if you want concurrency or resume on top of that, Spider already does it. just set start_urls, concurrent_requests, and an AsyncDynamicSession in configure_sessions.
@D4Vinci one idea though, spiders have no cli entry point at all right now, so something like scrapling crawl myspider.py would cover this without a second batch path in extract. happy to put up a pr for it if you like the shape.
@yetval Yes, it's in my mind to add in the future, but I have to approach it carefully.
@D4Vinci Ok I understand!