1

I tried searching but couldn't find anything specific to what I need.

So I want to fetch, maybe use curl for Windows, the guid string generated by this website without having to save the html file first. The sources are more or less like this:

<input name="YourGuidLabel" type="text" id="YourGuidLabel" onclick="this.focus(); this.select();" readonly="readonly" class="guidinput" value="852dd74c-4249-4390-85d3-6e9e2116ef2b" /></p>

What I want is this one: 852dd74c-4249-4390-85d3-6e9e2116ef2b. The string is then stored into a variable and echoed to view it.

In linux terminal I can do it in this simple way:

curl -s "https://www.guidgen.com/" | grep -o 'me="YourGuid.*value=.*/>' | cut -d '"' -f14

Does this thing by being able to use a batch file?.

0

3 Answers 3

2

This can do the trick with a batch file on Windows using a PowerShell Command and set it as variable with for /f .. do loop :


@echo off
Title Extract GUID Value from Input Field from site https://www.guidgen.com
@For /f %%a in ('Powershell -C "$(IWR https://www.guidgen.com -UseBasicParsing).InputFields.value"') do Set "GUID=%%a"
Echo GUID=%GUID%
pause
Sign up to request clarification or add additional context in comments.

Comments

0
@ECHO OFF
SETLOCAL
rem The following settings for the source directory and filename are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\q74909468.txt"

FOR /f "usebackqdelims=" %%e IN ("%filename1%") DO SET "html=%%e"
SET "html=%html:"=%"
SET "html=%html:<=%"
SET "html=%html:>=%"
SET "html=%html:)=%"
SET "html=%html:(=%"
SET "html=%html:;=%"
FOR %%e IN (%html%) DO if "%%e" neq "//p" SET "guid=%%e"

ECHO GUID=%guid%

GOTO :EOF

Always verify against a test directory before applying to real data.

Note that if the filename does not contain separators like spaces, then both usebackq and the quotes around %filename1% can be omitted.

You haven't told us where the html is located - I've presumed a file.

Sadly "more or less like" is not specific enough to generate a reliable solution.

Read the file line to a variable, html

Remove all " < > ) ( ; from that variable.

process the result, assigning each token in turn to guid, unless the token is //p

Assumes the required string is that string which precedes //p which is the last string in the (original text - deleted character set)

2 Comments

Thank you very much for your answer. What I want is to directly store the result into a variable and echo it to make the string visible. So, without having to save the html file first. Can you modify the code?. Btw, I've also edited my question.
Replace "%filename1%" with ` ' thecommandyouareusingtodownloadthefile '` and remove the usebackq keyword. It's important that ` ' thecommandyouareusingtodownloadthefile ' ` is single-quoted.
0

The following idea not using PowerShell may also perform the task you've laid out in your question.

@Echo Off & SetLocal EnableExtensions DisableDelayedExpansion
Set "value=" & For /F Delims^=^ EOL^= %%G In ('%SystemRoot%\System32\curl.exe -s "https://www.guidgen.com" ^| %SystemRoot%\System32\findstr.exe /RIC:" value=\"[0123456789abcdef][0123456789abcdef]*-[0123456789abcdef][0123456789abcdef]*-[0123456789abcdef][0123456789abcdef]*-[0123456789abcdef][0123456789abcdef]*-[0123456789abcdef][0123456789abcdef]*\""') Do (Set "value=%%G" & SetLocal EnableDelayedExpansion & For /F Delims^=^"^= %%H In ("!value:* value=!") Do EndLocal & Set "value=%%H")
If Defined value Echo %value% & Pause

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.