Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have never coded before using batch files and SED and have not coded at all in the last 5 years, but have a screen scraping program that I have been making changes to today. I added the sold_date field and the sale_price field. I got the sale_price field to work but can't get the date_field to work.
Here is the code:
set SOLDDATE=
SET AMOUNT=
set MATCHA=
grep -q "parcelID" ~ustax.htm
if ERRORLEVEL 1 goto __GANOREC
grep parcelID ~ustax.htm|sed "s/""/~/g" |cut -d"~" -f6|sed "1s/^/http\:\/\/www\.ustaxdata\.com\/nc\/wilson\//">~proplink
del ~ustax.htm
wget -q -nd -c -O ~ustax.htm -i ~proplink
sed -n "/Mailing/,/Property/p" ~ustax.htm|sed -n "6s/[<>]/~/gp"|cut -d"~" -f7>~tmp
for /f "delims==" %%R in (~tmp) do set ADDRESS=%%R
sed -n "/Mailing/,/Property/p" ~ustax.htm|sed -n "10s/[<>]/~/gp"|cut -d"~" -f7>~tmp
for /f "delims==" %%R in (~tmp) do set CITY=%%Rsed -n "/Sold/,/Valuation/p" ~ustax.htm|sed -n "2s/[<>]/~/gp"|cut -d"~" -f9>~tmp
for /f "delims==" %%R in (~tmp) do set SOLDDATE=%%Rsed -n "/Sold/,/Valuation/p" ~ustax.htm|sed -n "6s/[<>]/~/gp"|cut -d"~" -f9>~tmp
for /f "delims==" %%R in (~tmp) do set AMOUNT=%%RAnd here is the text of one of the webpages it's suppose to scrape
<TD bgcolor="#efefef">Sold Date</TD>
<TD bgcolor="#efefef"><div align="left"><strong></strong><strong>2003-01-31</strong></div></TD>
</TR>
<TR VALIGN=top bgcolor="#efefef">
<TD>Sold Amount $</TD>
<TD><div align="left"><strong>140,000</strong></div></TD>
</TR>
</TABLE>
</TD>
<TD WIDTH="33%">
<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="153A64">
<tr>
<td>Valuation
Information</td>TIA

Am I missing something? Why not just have
Set SoldDATE=%date%I only Batch if possible, 2000 more lines of code, oh well.

I'm trying to bring in dates from the website formatted YYYY-MM-DD, that code is bring in the current date.

Dude im still confused as to what you want... But if you want the date in yyyy-mm-dd format heres the code.
FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
SET date=%yyyy%-%mm%-%dd%
ECHO %date%
pauseI only Batch if possible, 2000 more lines of code, oh well.

Not to be ignorant dude, but I don't program. So where would the code go in relationship to the posted code? Up where everything is set or where I'm stripping the date out of the webpage? It's not the format I care about, it's just pulling out the date being displayed on the webpage. I've tried a lot of different things and I can't even get just the year to be written out. Thanks for your response.

Sorry, I gave you the wrong code... Apparently I a bieng ignorant :)
echo. | date | FIND "(mm" > NUL
If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
goto :EOF
:Parse-----
For /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
set %1=%%A&set %2=%%B&set YYYY=%%C
) else (
set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)(Set DateStamp=%YYYY%-%MM%-%DD%)
Ok you would write this at the very top of your code, and then where you want it to write your date, you simply type. %Datestamp%
I only Batch if possible, 2000 more lines of code, oh well.

... Im not to sure how to pull the date out...
I only Batch if possible, 2000 more lines of code, oh well.

BatchFreak, your revised code still doesn't do what the OP asked, which was to read an HTML file which contains a date somewhere inside it, and process that date (NOT today's date!)
To do that is difficult, so I won't attempt it.

"BatchFreak, your revised code still doesn't do what the OP asked,"
It's worse than that, Jim.
There is NO general substring code for %DATE% because the date layouts vary widely.
Somebody might be able to pull the date from the html, if we HAD the html. LOL
=====================================
If at first you don't succeed, you're about average.M2

Here you go M2, let me know if you need the whole page. I copied the HTML from my original post, let me know if you would like, I can send you the entire page.
<TD bgcolor="#efefef">Sold Date</TD>
<TD bgcolor="#efefef"><div align="left"><strong></strong><strong>2003-01-31</strong></div></TD>
</TR>
<TR VALIGN=top bgcolor="#efefef">
<TD>Sold Amount $</TD>
<TD><div align="left"><strong>140,000</strong></div></TD>
</TR>
</TABLE>
</TD>
<TD WIDTH="33%">
<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="153A64">
<tr>
<td>Valuation
Information</td>

@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('find "200" ^< mypage') do (
set str=%%a
)for /f "tokens=6 delims=<>" %%a in ("!str!") do (
echo %%a
)
=====================================
If at first you don't succeed, you're about average.M2

I had misunderstood him, I though he wanted todays date to be placed with the file.
I only Batch if possible, 2000 more lines of code, oh well.

![]() |
New skills
|
shortcut to HELP
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |