Solved

how do i do this?

Posted on 2004-09-27
6
219 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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