Solved

how do i do this?

Posted on 2004-09-27
6
218 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WMI, model #, retrieving information 10 117
topping3 challenge 14 70
move one pixel 4 58
Windows and other UI names - The Proper names for the Various elements! 1 61
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…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now