0

Trying to automate some ScreamingFrog (SF) website crawls, which can be done via Command Line (CL). I've created a bat file that sets some variables, tells CL where the .exe is, and runs the relevant commands within SF:

set domain=http://example.com

set company=ExampleCom

set crawlResults=C:\Users\brand\Documents\ScreamingFrog\Crawls

set sf=C:\Program Files (x86)\Screaming Frog SEO Spider\

set configFile=C:\Users\brand\Documents\ScreamingFrog\setup\ConfigSchedule.seospiderconfig

chdir /d "%sf%"

ScreamingFrogSEOSpiderCli.exe --config "%configFile%" --crawl "%domain%" --save-crawl --task-name "%company%" --headless --output-folder "%crawlResults%" --google-drive-account "account@example.com" --export-format "gsheet" --bulk-export "Response Codes:Client Error (4XX) Inlinks,Response Codes:Server Error (5XX) Inlinks"

I could create a .bat file for every domain/company - however, I was wondering if I could instead loop the .bat and replace the %domain% and %company% with the next pair from a list?

Apologies for my lack of expertise, I really appreciate anyone who takes a peek.

  • What about a text file with entries (lines) like `http://example.com;ExampleCom` and parsing it with `for /f "tokens=1,2 delims=;" %%a in (file.txt) do echo %%a - %%b`? – Stephan Aug 10 '22 at 18:21
  • This is definitely on the right path! I also like that it keeps a clean, easy to update txt file. I've made progress on that front and the bat now successfully grabs the parsed data, though unfortunately I lack the knowledge to adjust the bat to grab the first parsed results and throw it in the spot of %company% and %domain%, then loop around with the second parsed pair, etc. – BrandoRanked Aug 11 '22 at 18:07
  • You can either do it within the loop (see [here](https://stackoverflow.com/a/30284028/2152082) for an example and it's caveats) or use `call` with parameters to call a subroutine. Update your question with your new code when you need more help. – Stephan Aug 11 '22 at 20:03

1 Answers1

0

(untested) The following should do fine:

@echo off
setlocal

set "crawlResults=C:\Users\brand\Documents\ScreamingFrog\Crawls"
set "sf=C:\Program Files (x86)\Screaming Frog SEO Spider\"
set "configFile=C:\Users\brand\Documents\ScreamingFrog\setup\ConfigSchedule.seospiderconfig"

chdir /d "%sf%"

for /f "skip=1 tokens=1,2 delims=;" %%a in (data.csv) do (
  ECHO ScreamingFrogSEOSpiderCli.exe --config "%configFile%" --crawl "%%a" --save-crawl --task-name "%%b" --headless --output-folder "%crawlResults%" --google-drive-account "account@example.com" --export-format "gsheet" --bulk-export "Response Codes:Client Error (4XX) Inlinks,Response Codes:Server Error (5XX) Inlinks"
)

with contents of data.csv like:

Domain;Company
http://example.com;Example
http://guugle.com;Searcher
http://sellstuff.com;E-Shop

Remove the ECHO after verifying it does work as intended.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • I appreciate this! Unfortunately, when running the bat I get an error that > The system cannot find the file Companies.csv. Interestingly when implementing the above suggested: > for /f "tokens=1,2 delims=;" %%a in (Companies.txt) do echo %%a - %%b The CL does return the Domain - Company, it just can't find it once nested in this fashion – BrandoRanked Aug 15 '22 at 20:28
  • Try to give it the absolute path (`D:\rive\folder\companies.csv`) – Stephan Aug 15 '22 at 21:51