Solved

how do i do this?

Posted on 2004-09-27
6
221 Views
Last Modified: 2010-05-18
i'm trying to get a piece of information froma webpage, the page looks something like this but larger.



}
// -->
</script>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="http://ima.weather.com/common/header/javascript/ext.js" ></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="http://ima.weather.com/common/header/javascript/triggerParams.js" ></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="http://ima.weather.com/common/header/javascript/stdLauncher.js" ></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="http://ima.weather.com/common/header/javascript/divtools.js" ></SCRIPT><SCRIPT LANGUAGE="JavaScript1.2">
<!--

TD class="blkVerdanaText10">
// <!--#if expr="" -->
var remoteAddr
// <!--#endif -->
//

i want to get a part of this text let say it was: blkVerdanaText10

how would i find it and extract the text between TD class=" and ">
0
Comment
Question by:andyakira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12166880
#!/usr/bin/perl
use LWP::Simple;
print "$1\n" if get("http://www.website.org/page.html") =~ /TD class="(.*?)">/;

0
 
LVL 6

Expert Comment

by:edey
ID: 12166916
What language? What platform? How are you getting the html?
0
 
LVL 5

Expert Comment

by:WesleySaysHi
ID: 12167298
Copy the code below and save it as html file, then run the file from your browser.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<Table>
<tr>
<TD class="blkVerdanaText10">data</TD>
</tr>
</Table>
<script language="javascript">
yourdata=document.getElementsByTagName('TD')[0];
yourclass=yourdata.getAttribute('className');
document.write(yourdata)
document.write('<br>')
document.write(yourclass)
</script>
</body>
</html>

I wrote the code so that you can see how you can read both the content of the table cell and the attribute of the TD tag:
1. yourdata is the variable in which I read the content of the table cell
2. yourclass is the variable that reads the class attribute of the TD tag
3. both variables are written on screen by the document.write statements

You are interested in fact by the getAttribute method applied to the object.
 
Adapt the code to your program.

Regards,
Wesley
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:andyakira
ID: 12174931
im working in VB, sorry for the late reponse.  i thought i postedin the vb section.
0
 
LVL 5

Expert Comment

by:WesleySaysHi
ID: 12175114
The "getElementsByTagName" and "getAttribute" can be used in VB.net too. I'm not going to write another code now in VB, but...

I understand that you want to have some code written in VB.NET for getting information from a webpage, therefore I'm giving you this link:

http://www.eggheadcafe.com/articles/20031027.ASP

Scroll to the middle of the page and you will find the VB code. At the bottom of the page you also have a download option. Things are very good explained there. I don't think you'll need further help.

Regards,
Wesley
0
 
LVL 8

Accepted Solution

by:
SNilsson earned 500 total points
ID: 12311400

Here you are, this function will return the page source as a string.
You can then use functions as Substring to parse the text.


  Public Function GrabHtmlSource(ByVal sUrl As String) As String

        Dim req As System.Net.WebRequest
        Dim oResult As System.Net.WebResponse
        Dim oReceiveStream As System.IO.Stream
        Dim oEncode As System.Text.Encoding
        Dim bRead() As Byte
        Dim iBytes As Integer
        Dim sSource As String

        Try
            oEncode = System.Text.Encoding.GetEncoding(1252)
            req = System.Net.WebRequest.Create(sUrl)
            oResult = req.GetResponse()
            oReceiveStream = oResult.GetResponseStream()
            bRead = New Byte(512) {}
            iBytes = oReceiveStream.Read(bRead, 0, 512)

            While (iBytes > 0)
                sSource = sSource & oEncode.GetString(bRead, 0, iBytes)
                iBytes = oReceiveStream.Read(bRead, 0, 512)
            End While
            Return sSource
        Catch Ex As Exception
            Return ""
        Finally
            oReceiveStream = Nothing
        End Try
    End Function
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
storing csv file in table variable in Python 2 94
troubleshoot a python script 8 113
IDE for Python 5 104
CSV file copy field 1 to field 2 2 62
This article will show, step by step, how to integrate R code into a R Sweave document
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question