Home > Net >  Batch file to capture information from a website
Batch file to capture information from a website

Time:01-29

I want to get these informations from this website :
1. Day
2. Month
3. Year
4. Time
https://www.timeanddate.com/worldclock/fullscreen.html?n=37

how can i do this?

The best way would be to save all of them in different variables I would say and probably download the information with curl -o random.txt link

I already tried something like this :

curl -s -o r.txt link
set /p V=<r.txt
set V=%V:~4%

I'm sure there's a way easier and better way...

CodePudding user response:

Try this:

@if (@x)==(@y) @end /***** jscript comment ******
     @echo off
     cscript //E:JScript //nologo "%~f0" "%~nx0"  | findstr /r /e "[0123456789]"
     exit /b %errorlevel%

***** end comment *********/

var strURL = "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"
var ieOBJ = new ActiveXObject("InternetExplorer.Application");
ieOBJ.Visible = false
ieOBJ.Navigate2(strURL)


do {
    WScript.Sleep(100);
} while (ieOBJ.Busy);


var innerText=ieOBJ.document.body.innerText;
WScript.Echo(innerText);
ieOBJ.Quit()

It should be a file with a .bat extension.

CodePudding user response:

So you're basically asking how to extract specific information from a website. You'll need an HTML-parser like for that:

xidel -s "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"^
  -e "tokenize(//div[@id='i_date'])[position() gt 1],//div[@id='i_time']"
28
January
2023
21:53:02

We grab the text-node from <div id=i_date>, convert it to a sequence by "tokenizing" on the white-space and only show item 2, 3 and 4. The text-node from <div id=i_time> we grab as-is.

To export these to a cmd-variable:

FOR /F "delims=" %A IN ('
  xidel -s "https://www.timeanddate.com/worldclock/fullscreen.html?n=37"
    -e "let $a:=tokenize(//div[@id='i_date']) return ($day:=$a[2],$month:=$a[3],$year:=$a[4]),$time:=//div[@id='i_time']"
    --output-format^=cmd
') DO %A

ECHO            
  • Related