Solved

how do i do this?

Posted on 2004-09-27
6
217 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
Comment Utility
#!/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
Comment Utility
What language? What platform? How are you getting the html?
0
 
LVL 5

Expert Comment

by:WesleySaysHi
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

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

Expert Comment

by:WesleySaysHi
Comment Utility
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
Comment Utility

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now