?
Solved

how do i do this?

Posted on 2004-09-27
6
Medium Priority
?
223 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

762 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