Fetch and record specific HTML feild

February 9, 2010 at 08:28:44
Specs: Windows XP
Hi guys, i was looking for some script ( perl/python/batch) which is able to fetch a specific field/div/class/id from a HTML page and record it in CSV file with a time stamp

this thing is purely possible in perl and python but unfortunatly i m not a coder and it will take long time to learn these languages so please help

Link is this

and i want to fetch and record this code, acctually its speed of dsl link , i want to keep record if it

                  <td> </td>

                  <td class='hd' width=48>Downstream</td>
                  <td class='hd' width=48>Upstream</td>
                  <td class='hd'>Rate (Kbps)</td>
                  <td id="downrate">2044 </td>
                  <td id="uprate">507 </td>


any help will be appreciated


See More: Fetch and record specific HTML feild

Report •

February 9, 2010 at 10:33:50
It's neither Python, nor Perl, nor batch, so I hope you don't have anything against VBScript.
err = Main
WScript.Echo "Done"
WScript.Quit err

Function Main
  Set ie = CreateObject("InternetExplorer.Application")
  ie.Visible = False
  nav = "http://admin:password@"
  ie.Navigate nav
  Wait ie
  With ie.Document
    dr = Trim(.getElementByID("downrate").innerText)
    ur = Trim(.getElementByID("uprate").innerText)
  End With
  With CreateObject("Scripting.FileSystemObject")
    .OpenTextFile("csv.csv", 8, True).WriteLine Now & "," & dr & "," & ur
  End With
End Function

Sub Wait(ie)
      WScript.Sleep 200
    Loop While ie.ReadyState < 4 Or ie.Busy
    WScript.Sleep 1000
  Loop While ie.ReadyState < 4 Or ie.Busy
End Sub

Report •

February 9, 2010 at 12:07:23
Thanks for quick response , its giving error like this

Line : 9
Char: 3
Error: 0x800C000E
Code: 800C000E
Source: (null)

Report •

February 9, 2010 at 12:38:09
For some reason, Internet Explorer is either refusing to come up, or its launching so slowly, it refuses to navigate to that page.

Before the line

ie.Navigate nav
add the following line:
WScript.Sleep 3000

Report •

Related Solutions

February 9, 2010 at 12:51:29
same error :-s

Line : 10
Char: 3
Error: 0x800C000E
Code: 800C000E
Source: (null)

update : i got the reason

IE is not sporting this URL

nav = "http://admin:password@"

it worked when i changed it to

but it asked for login details

Report •

February 10, 2010 at 08:30:50
Just tell me how to print the output in popup/msg box
something like this

MsgBox "Down rate is = ", 0, "Stream Notice"

Report •

February 10, 2010 at 13:23:53
MsgBox ("Down rate is = "& 0& " Stream Notice"

wscript.echo "Down rate is = "& 0& " Stream Notice"

as for obtaining the value, is there any compelling reason you have to use browser to get the html from remote?
what about:
copy \\\dslinfo_en.html .
then use the browser on the local (thereby avoiding passwords)
you might also be able to:
but then of course you have to read/search/parse out the desired information as text.

Report •

February 10, 2010 at 14:16:09
can u make it without using browser ? , cuz its bit heavy to use browser and its slow

Thanks for your help

Report •

February 10, 2010 at 18:49:26
depends on if the file is accessible to your system. to test if it is or not, try running this bat:
findstr "uprate downrate" \\\dslinfo_en.html

and see if it reads the target values from the file. might just be able to use "findstr" to grab the data that way.
if it accessible to the batch, then yes, it can be done without the browser being involved. let me know what happens...

Report •

February 11, 2010 at 12:45:09
well nothing happened it just crashed and you trying to fetch data from page but that is like HTTP , i dont think batch support that

just tell me what will be the code in vbs for something like that ,
If Downrate is blank then this erorr comes up

May you make it in cases like

If dr is blank then check again dr with some delay

If dr is below 1000 then some code

If dr is above 1000 then some other code like echo something
Ping id address

If it find TTL ( means okay )
then ,
Perform some code

Else ( eorr in ping )
Perform some code
How to send command like, batch command
Start /d "C:\Program Files\" some.exe

Million thanks

Report •

February 15, 2010 at 06:06:29
@ nbrane

hey mate i got this utility which save the html page so fast with batch , URL2File

URL2File h**p://admin:password@ test.htm

findstr "uprate downrate" test.htm

and it works, may you help further ? please

Report •

February 15, 2010 at 09:06:17
In general, it's best to avoid trying to parse HTML/XML/XHTML with batch scripts.

According to MS Support, if you want to get my script to work, you need to (create and) set the registry DWORDs

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE\iexplore.exe
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE\explorer.exe
to 0.

Report •

February 15, 2010 at 11:53:24
That sounds a lot like "wget", which i was going to suggest at one point and decided not as it is "not native to windows" and requires a download from sourceforge or gnu utils.
Assuming the output of the "findstr",
findstr /l /i "downrate uprate" url.fil > file

<td id="downrate">2044 </td>
<td id="uprate">507 </td>

then here's a klutzy way to avoid using batch with the <> but you need to use notepad or edit to make the pipe-file edlin.in:
1,#r<td id="downrate">^Z
1,#r </td>^Z

this file only needs to be created one time, then it can be used over and over by the script.
Then, in script:
edlin file<edlin.in>nul

"file" now contains just the two numbers.

but script can do it without too much problem:

for /f "tokens=3 delims=^<^> " %%a in (file) do (
if not defined bb set bb=%%a
set aa=%%a
echo up is %aa%
echo down is %bb%

char.s <>|= get messy in batch, as Razor pointed out, but since it's just the two lines maybe this script will work ok.
ps: that registry setting is good to know, i have it filed away now into my notes.

Report •

February 15, 2010 at 14:17:37
thanks Razor2.3 for pointing out the real problem

thanks nbrane for your different idea and effort
and m moving further with VBScript cuz its better now

the major problem is solved now :D

Report •

Ask Question