Jump to content

Recommended Posts

Posted

I want to search for a string in an html file. The line I need contains a number which constantly changes. There isn't anything else on this line which is unique. Therefore, I would have to search for the line above.

Here's is a small part of the html document:

Total
</TD>
<TD COLSPAN="3" HEADERS="Total">
184394</TD>
</TR>
</TABLE>

The number "184394" is the information I need but its a different number each time the webpage is saved (I'm using Downloader.exe to save it)

The first problem, is if I search for "TD COLSPAN=" it finds 3 instances in the file. I cant specify a longer string becasue the quotation marks mess it up but maybe there is a way around this?

Here's the code I have so far:

downloader.exe -download http://192.168.0.94/m_s_cnt.htm  lobby.htm
FIND "TD COLSPAN" "lobby.htm" >>lobby.text

How can I grab the next line down from the search string "TD COLSPAN="? Ive checked all the switches for both the Find and Findstr commands, but I cant see anything useful. I dont know enough about scripting to be able to work it out.

Here's the full HTML file if anyones interested (its the page counter from a network printer)

lobby.htm


Posted

findstr /b "[0-9].*</TD>" lobby.txt

/b start at the beginning of the line.

[0-9].* looks for a digit which can be repeated until </TD> is reached

-John

Posted

Your solution work's thank you very much. However, a total of 7 lines match the string:

97727</TD>
1806</TD>
32860</TD>
86981</TD>
492</TD>
8028</TD>
184708</TD>

I modified the code to add a line number and then I added another line to use the line number as a string:

findstr /b /n "[0-9].*</TD>" Lobby.htm > temp.txt
echo Page count for the WHSE Lobby printer > total.txt
findstr "140" temp.txt >> total.txt
del temp.txt

This resulted in the following:

Page count for the WHSE Lobby printer 
140:184708</TD>

I wasn't very happy with having "140:" and "</TD>" so I did a search using google and found Munge.exe from the NT4 Resource Kit which can replace strings. I tried it out and it worked perfectly. Here's the new code:

findstr /b /n "[0-9].*</TD>" Lobby.htm > temp.txt
echo Page count for the WHSE Lobby printer > total.txt
findstr "140" temp.txt >> total.txt
MUNGE munge.txt -l -t total.txt
del temp.txt

munge.txt contains the following:

"140:" ""
"</TD>" ""

When I run the script, I get the following which I'm very happy with:

Page count for the WHSE Lobby printer 
184708

I've got another 6 html files to retrive some numbers from so I'll continue with it on Monday. Some of them will require some numbers to be added up so I'll try a command line calculator.

Posted

Thanks for the help guys, I've almost finnished.

Just one more thing though, how can I SET the output of the FINDSTR command to a variable instead of to a txt file?

I've tried the following but it sets the actual command as the variable instead:

SET total="findstr "[0-9]" total.txt"

Posted
Thanks everyone for your help, especially to jftuga :)

" Bath file "... I lol'd :lol:

Did I miss something? :}

The topic title. Just don't drop the soap.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...