Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem saveBook from gutenberg.spiegel.de
- setlocal EnableDelayedExpansion
- set "bookTitle=ulenspiegel"
- rem die erste Seite des buchs ist http://gutenberg.spiegel.de/buch/ulenspiegel-2462/1
- rem die 1 wird weggelassen und durch die Seitennummer ersetzt
- set "GutenbergBaseUrl=http://gutenberg.spiegel.de/buch/ulenspiegel-2462/"
- set "textBlockStart=\<div id=\"gutenb\"\>"
- set "textBlockEnd=\<\/div\>"
- set /a "firstSubsite=1"
- set /a "lastSubsite=14"
- set "destinationPath=%~dp0savedSites"
- md "%destinationPath%" 2>nul
- set destinationFile=%destinationPath%\%bookTitle%
- set "finalHtmlFile=%destinationPath%\%bookTitle%.html
- :main
- rem alle Webseiten die zum Buch gehören lokal speichern
- for /l %%c in (%firstSubsite%,1,%lastSubsite%) do (
- call :saveSites "%GutenbergBaseUrl%%%c" "%destinationFile%%%c.txt"
- )
- rem neue Html-Seite erzeugen
- echo ^<html^> >"%finalHtmlFile%"
- echo ^<body^> >>"%finalHtmlFile%"
- rem den Inhalt des div-containers <div id="gutenb">" in jeder runtergeladenen Webseite in die neue locale webseite schreiben.
- for /l %%c in (%firstSubsite%,1,%lastSubsite%) do (
- call :parse "%destinationFile%%%c.txt"
- )
- echo ^<body^> >>"%finalHtmlFile%"
- echo ^<html^> >>"%finalHtmlFile%"
- echo fertig
- start "" "%finalHtmlFile%"
- pause
- exit
- :saveSites
- echo download %1 to %~nx2
- powershell -command "&{$url = '%~1';$path = '%~2';$client = New-Object System.Net.WebClient;$client.DownloadFile($url, $path)}"
- exit /b
- :parse
- call :find1stLine2read "%~1"
- for /F "skip=%firstLine2Read% delims=" %%a in ('type "%~1"') do (
- set nixdummy=%%a
- set nixdummy|FINDSTR /ic:"\<\/div\>" >nul && goto breakParse|| echo. %%a >>"%finalHtmlFile%" & echo. %%a
- )
- :breakParse
- exit /b
- :find1stLine2read
- for /f "usebackq delims=:" %%a in (`findstr /nic:"%textBlockStart%" "%~1"`) do (
- set /a "firstLine2Read=%%a"
- )
- exit /b
Advertisement
Add Comment
Please, Sign In to add comment