Call fails

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Call fails

#1 Post by doscode » 15 Jun 2012 10:30

What is wrong with Call here? When I call the subroutine :download, help is printed.

Code: Select all

@echo off 
Setlocal EnableDelayedExpansion
SET proxy=Proxy.htm
SET proxy_2=Proxy_1.htm         

SET source_1=http://www.samair.ru/proxy
SET source_2=http://www.proxynova.com/proxy-server-list/


CHCP 1250 > NUL

for /f "delims=" %%x in (delimiter.ini) do set TAB=%%x
 
if not exist %proxy% (
  echo File not found
  pause
  exit
)

REM http://www.samair.ru/proxy/
FOR /F "tokens=7,12,15 delims=<>" %%A IN ('grep -B 25 "</td></tr></tbody></table>" %proxy% ^| grep high') DO ( echo %%B %%A %%C  )

pause

Echo Gonna download from proxynova.com
FOR %%N IN (1,2,3,4,5,6,7,8,9,10) DO CALL :download http://www.proxynova.com/proxy-server-list/?p=%%N

pause

REM one more loop to add .. FOR .. IN dir proxy_*
REM http://www.proxynova.com/proxy-server-list/
FOR /F "tokens=3,4,5 delims=<>" %%A IN ('grep -B 810 -E "<th colspan=.10.>&nbsp;</th>" %proxy_2% ^| grep -E ^"row_proxy^|port^|country^|proxy_^" ') DO (
  if "%%C" == "/span" SET ip=%%B
  if "%%C" == "/a" SET port=%%B
  if "%%B" == "/a" SET location=%%A
  if "%%B" == "/span" (
    SET A=%%A
    SET A=!A:"=$!
    FOR /F "tokens=1,2,3 delims=$ " %%S IN ("!A!") DO (
    SET type=%%U
    SET ready=1
    )
  )
if !ready!==1 (
  echo IP:!ip!:!port! in !location! is !type!
  SET ready=0
  pause
)
)
exit /b

:download
echo %1
pause
SET user_agent="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8"
SET accept="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
SET accept_language="Accept-Language: en-us,en;q=0.5"
SET accept_charset="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
SET keep_alive="Keep-Alive: 300"
SET connection="Connection: keep-alive"
SET url=http://request.urih.com/
del proxy_%1.htm
REM curl -o proxy_%1.htm -H %user_agent% -H %accept% -H %accept_language% -H %accept_charset% -H %keep_alive% -H %connection% %1
pause
GOTO :eof
Last edited by doscode on 15 Jun 2012 11:55, edited 1 time in total.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Call fails

#2 Post by Squashman » 15 Jun 2012 10:56

You need to put Quotes around the variable you are passing to the download function.

Code: Select all

FOR %%N IN (1,2,3,4,5,6,7,8,9,10) DO CALL :download "http://www.proxynova.com/proxy-server-list/?p=%%N"


You know there is such thing as a FOR /L loop.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: Call fails

#3 Post by doscode » 15 Jun 2012 12:21

Thanks. This looks great now:

Code: Select all

@echo off 
Setlocal EnableDelayedExpansion
SET proxy=Proxy.htm
SET proxy_2=Proxy_1.htm         

SET source_1=http://www.samair.ru/proxy
SET source_2=http://www.proxynova.com/proxy-server-list/

for /f "delims=" %%x in (delimiter.ini) do set TAB=%%x
 
if not exist %proxy% (
  echo Soubor s proxy servery nenalezen! Konec.
  pause
  exit
)

REM http://www.samair.ru/proxy/
FOR /F "tokens=7,12,15 delims=<>" %%A IN ('grep -B 25 "</td></tr></tbody></table>" %proxy% ^| grep high') DO ( echo %%B %%A %%C  )

FOR /L %%N IN (1,+1,10) DO CALL :download "http://www.proxynova.com/proxy-server-list/?p=%%N" %%N

pause

REM http://www.proxynova.com/proxy-server-list/
FOR %%Z IN (proxy_*.htm) DO (
FOR /F "tokens=3,4,5 delims=<>" %%A IN ('grep -B 810 -E "<th colspan=.10.>&nbsp;</th>" %proxy_2% ^| grep -E ^"row_proxy^|port^|country^|proxy_^" ') DO (
  if "%%C" == "/span" SET ip=%%B
  if "%%C" == "/a" SET port=%%B
  if "%%B" == "/a" SET location=%%A
  if "%%B" == "/span" (
    SET A=%%A
    SET A=!A:"=$!
    FOR /F "tokens=1,2,3 delims=$ " %%S IN ("!A!") DO (
    SET type=%%U
    SET ready=1
    )
  )
if !ready!==1 (
  echo IP:!ip!:!port! in !location! is !type!
  SET ready=0
)
)
)
exit /b

:download
SET user_agent="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8"
SET accept="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
SET accept_language="Accept-Language: en-us,en;q=0.5"
SET accept_charset="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
SET keep_alive="Keep-Alive: 300"
SET connection="Connection: keep-alive"
SET url=http://request.urih.com/
del %1 2>NUL
Echo Gonna download from proxynova.com
curl -o proxy_%2.htm -H %user_agent% -H %accept% -H %accept_language% -H %accept_charset% -H %keep_alive% -H %connection% %~1
GOTO :eof


I have one more site which I want to proceed but this one is a little bit harder than the previous ones. There is very confusing the part of tags with IP
http://www.hidemyass.com/proxy-list/

Post Reply