store webpage data...help??

sourind

New member
Joined
Apr 5, 2006
Messages
4
Programming Experience
1-3
suppose,i go to webpage filled with numeric data ...and i want to store them(read them) and save in a file(or string)....how to do that?
 
VB.NET:
Dim client As New WebClient()
Dim data As Stream = client.OpenRead("[URL="http://yahoo.com/"]http://yahoo.com[/URL]")
Dim reader As New StreamReader(data)
Dim results As String = reader.ReadToEnd()
now pars results to get what you want and save to a file or whatever.

btw this is the wrong forum for this
 
Last edited by a moderator:
You can take advantage of the MSHTML control to easier get to the relevant tags that may contain the data. Add Reference and browse the COM page to add it.

Here is an example using it to get the Wired.com Technology news headers. I first viewed and analyzed the html source of that page, found that the headers is in A tags that are marked with class="hd" attribute. In code this translates to first get a collection of all A tag, then check the collection for class attributes where value is "hd".
VB.NET:
Dim html As New mshtml.HTMLDocument
Dim doc As mshtml.IHTMLDocument2 = html
doc.write("<html></html>") 'trick to initialize IPersistStreamInit
doc.close()
doc = html.createDocumentFromUrl("http://www.wired.com/technology.html", vbNullString)
While doc.readyState <> "complete"
   Application.DoEvents() 'just waiting for asynchronous load webpage
End While
html = doc
Dim ihec As mshtml.IHTMLElementCollection
ihec = html.getElementsByTagName("a")
Dim sb As New System.Text.StringBuilder
Dim att As Object
For Each ihe As mshtml.IHTMLElement In ihec
   att = ihe.getAttribute("className")
   If Not att Is Nothing Then
      If att.ToString = "hd" Then
         sb.AppendLine(ihe.innerText)
      End If
   End If
Next
MsgBox(sb.ToString)
 
Back
Top