Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get a variable values from html file using vbscript?

1,810 views
Skip to first unread message

Jaya prakash

unread,
Oct 28, 2010, 2:10:24 AM10/28/10
to
hi all,
I working in Vbscript. i would like to read a tag values from Html
file using vbscript?
then how to open all files from the folder? i need to enter the values
in a excal sheet what i get from the html file.


Html file getting values from some server...so i ve to get that value
and update in an excel file..

EX:

Html files contains value of Total users 50. This 50 is changed when
we open the next html file.How to get this value?
suggest me...
Thankyou ,
Jayaprakash S

Evertjan.

unread,
Oct 28, 2010, 4:22:24 AM10/28/10
to

I suppose you do not mean with infile vbs in IE,
as that can be done by .innerHTML.

Do you mean feeding the content of a html file as a text-string
to a vbscript?

I would just use regex identify the part of that string I am interested in,
and replace all text except that value.

"bla bla<span id='a1'>50</span> blah blah"

/^.*?<span id='a1'>(\d+)<\/span>.*$/

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jaya prakash

unread,
Oct 28, 2010, 8:42:51 AM10/28/10
to

ya..thanks Everjan..but i don ve any id r name to access on the table
yar..my html file contains full of tables..i dono how to diff the
tables to the reader( vb Script)..


i have table like this

<Table width="90">
.....
<td>total users</td>
<td> 5</td>
.....
</table>

how can i get that 5 value using Vb script?

Thanks,
Jayaprakash S

Mayayana

unread,
Oct 28, 2010, 9:54:03 AM10/28/10
to
i have table like this

<Table width="90">
.....
<td>total users</td>
<td> 5</td>
.....
</table>

how can i get that 5 value using Vb script?

-----------------

There are basically two methods:

1) The all collection represents all elements
in the page. You can go through that to find
the element you need. Any property valid for
an element is accessible through all.

2) If you need to access the page later you
should asign IDs in the first place. If you
had written:

<Table ID="TableTotalUsers" width="90">

then you could just use:

TableTotalUsers.innerText

to get what you need. Unfortunately, TD does not
have an innerText property, so you have to access
the parent table.


Evertjan.

unread,
Oct 28, 2010, 9:54:01 AM10/28/10
to
Jaya prakash wrote on 28 okt 2010 in microsoft.public.scripting.vbscript:

>> "bla bla<span id='a1'>50</span> blah blah"
>>
>> /^.*?<span id='a1'>(\d+)<\/span>.*$/

[please do not quote signatures on usenet]



> ya..thanks Everjan..but i don ve any id r name to access on the table
> yar..my html file contains full of tables..i dono how to diff the
> tables to the reader( vb Script)..
>
>
> i have table like this
>
> <Table width="90">
> .....
> <td>total users</td>
> <td> 5</td>

Not much difference, just use regex to delete [replace with empty]
as much as possible. This is just trial and error the first times you try
it, but you will get the hang of it.

Why would you want to use VBS by the way, but to accomodate for the
feelings of this NG, as Javascript can do the same and can do it much
prettier?

Using cscript or wscript has the same effect using vbs or js.

Dave "Crash" Dummy

unread,
Oct 28, 2010, 12:07:42 PM10/28/10
to
Mayayana wrote:
> i have table like this
>
> <Table width="90">
> .....
> <td>total users</td>
> <td> 5</td>
> .....
> </table>
>
> how can i get that 5 value using Vb script?
>
> -----------------
>
> There are basically two methods:
>
> 1) The all collection represents all elements
> in the page. You can go through that to find
> the element you need. Any property valid for
> an element is accessible through all.

The preferred method is
Set tbl=document.getElementsByTagName("table")(n)

> 2) If you need to access the page later you
> should asign IDs in the first place. If you
> had written:
>
> <Table ID="TableTotalUsers" width="90">
>
> then you could just use:
>
> TableTotalUsers.innerText
>
> to get what you need. Unfortunately, TD does not
> have an innerText property, so you have to access
> the parent table.

Yes, it does. In the example, it would be

txt=TableTotalUsers.rows(r).cells(c).innerText

You could also include id's in the cells of interest and access them
directly.

<TD id="bingo">text of interest</TD>

txt=bingo.innerText

Here is a simple HTML page that will illustrate using the
GetElementsByTagName method.

<html><body>
<table>
<tr><td>R0C0</td><td>R0C1</td><td>R0C2</td></tr>
<tr><td>R1C0</td><td>R1C1</td><td>R1C2</td></tr>
<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td></tr>
</table>
<script type="text/vbs">
set tbl=document.getElementsByTagName("table")(0)
document.write tbl.rows(1).cells(1).innerText
</script>
</body></html>

--
Crash

Money may not buy happiness, but it can sure defray a lot of unhappiness.

Mayayana

unread,
Oct 28, 2010, 2:53:51 PM10/28/10
to

| > 1) The all collection represents all elements
| > in the page. You can go through that to find
| > the element you need. Any property valid for
| > an element is accessible through all.
|
| The preferred method is
| Set tbl=document.getElementsByTagName("table")(n)
|

That's not in the IE4 DOM that I have docs for.
Maybe it started with IE5? If it's one of the
newer non-quirks-only methods I'd avoid it. In
any case, I don't see any reason, in most cases,
that either should be necessary excpet when parsing
an unknown page.

| > to get what you need. Unfortunately, TD does not
| > have an innerText property, so you have to access
| > the parent table.
|
| Yes, it does. In the example, it would be
|
| txt=TableTotalUsers.rows(r).cells(c).innerText
|

Interesting. I never noticed that before. Not
as good as being able to reference the ID of a
specific TD, but better than nothing.

| You could also include id's in the cells of interest and access them
| directly.
|
| <TD id="bingo">text of interest</TD>
|
| txt=bingo.innerText
|

I guess I need to update my copy of MSDN.
I have IE6 and it works as you say, but my older
docs don't list innerText for a TD.

Dave "Crash" Dummy

unread,
Oct 28, 2010, 4:01:16 PM10/28/10
to
Mayayana wrote:
> | > 1) The all collection represents all elements
> | > in the page. You can go through that to find
> | > the element you need. Any property valid for
> | > an element is accessible through all.
> |
> | The preferred method is
> | Set tbl=document.getElementsByTagName("table")(n)
> |
>
> That's not in the IE4 DOM that I have docs for.
> Maybe it started with IE5? If it's one of the
> newer non-quirks-only methods I'd avoid it. In
> any case, I don't see any reason, in most cases,
> that either should be necessary excpet when parsing
> an unknown page.

http://msdn.microsoft.com/en-us/library/ms536439(VS.85).aspx
http://www.bing.com/search?q=site:microsoft.com+GetElementsByTagName

> | > to get what you need. Unfortunately, TD does not
> | > have an innerText property, so you have to access
> | > the parent table.
> |
> | Yes, it does. In the example, it would be
> |
> | txt=TableTotalUsers.rows(r).cells(c).innerText
> |
>
> Interesting. I never noticed that before. Not
> as good as being able to reference the ID of a
> specific TD, but better than nothing.

Much better than nothing if you need to access multiple cells
in a table, like all column 3 items, or sort the table rows.

> | You could also include id's in the cells of interest and access them
> | directly.
> |
> | <TD id="bingo">text of interest</TD>
> |
> | txt=bingo.innerText
> |
>
> I guess I need to update my copy of MSDN.
> I have IE6 and it works as you say, but my older
> docs don't list innerText for a TD.

I think innerText is only valid with IE, but then, so is VBS. It may not
work with Firefox running JavaScript.

--
Crash

Atheism is a matter of faith, too.

Dave "Crash" Dummy

unread,
Oct 28, 2010, 4:15:07 PM10/28/10
to
Mayayana wrote:
> | > 1) The all collection represents all elements
> | > in the page. You can go through that to find
> | > the element you need. Any property valid for
> | > an element is accessible through all.
> |
> | The preferred method is
> | Set tbl=document.getElementsByTagName("table")(n)
> |
>
> That's not in the IE4 DOM that I have docs for.
> Maybe it started with IE5? If it's one of the
> newer non-quirks-only methods I'd avoid it. In
> any case, I don't see any reason, in most cases,
> that either should be necessary excpet when parsing
> an unknown page.

Go to the description of the all collection and read the
Community Comment at the bottom of the page.
http://msdn.microsoft.com/en-us/library/ms537434(VS.85).aspx

--
Crash

Life is short. Eat dessert first.

Mayayana

unread,
Oct 28, 2010, 6:45:56 PM10/28/10
to
| Go to the description of the all collection and read the
| Community Comment at the bottom of the page.
| http://msdn.microsoft.com/en-us/library/ms537434(VS.85).aspx
|

I see. Good to know. Though I've never scripted
for anything but IE, anyway. I use it for HTAs, and
I use it on my own website to make up for IE
shortcomings. But in general I avoid all web scripting.
I don't enable it in the browser myself and consider
any page that *must use* script as a faulty page.

(Of course all the kids Facebooking their way into
Web 2.0 would disagree we me on that. :)


Dave "Crash" Dummy

unread,
Oct 29, 2010, 8:04:51 AM10/29/10
to

I also write VBScript exclusively for local use in HTA, VBS and
HTML/IE. I don't include client side script in public web pages, and the
*nix server that hosts my web site doesn't do ASP. I use mostly PHP for
server side scripts, with a taste of Perl when I can't avoid it. Still,
I like to stay current and kosher with my local code.
http://msdn.microsoft.com/en-us/library/ms533043(v=VS.85).aspx
--
Crash

"The future ain't what it used to be."
~ Yogi Berra ~

0 new messages