Results 1 to 8 of 8

Thread: Quickest way to get a page/Most control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    7

    Quickest way to get a page/Most control

    I have been using VB (vba actually) for a while to download pages from the web for parsing...now I am trying to integrate the scripts into a super duper VB program to do the same, and trying to get everything right. I have used both IExplorer (i think that is the class--the one that wraps with WebBrowser) and MSXML2.ServerXMLHTTP to do this. I know there are a couple other technologies out there to do the same...

    So my question is, what is the quickest (as in shortest time from .navigate or its equivalent) to getting the page into a buffer. My other question is, what object gives you the most control over the actions of your internet control...specifically, I would like to be able to throttle a connection down at certain points of the day, and send it back up again at night. What will let me do this?

    Finally, which of the technologies is best for reading data as it streams in?

    These are not necessarily big files but there are A LOT of them, and they are chained together, with pages leading to other pages, etc.

    So to sum up, what do you think would be my best bet? Thanks tons.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    7

    Re: Quickest way to get a page/Most control

    btw, VB 2005 Express edition...i didnt see winsock in the list of controls...though i may be wrong.

  3. #3
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Quickest way to get a page/Most control

    you can use the HTTPWebRequest to get the HTML source of a page. This function does that:

    at the top of your code you need:

    VB Code:
    1. Imports System.Net
    2. Imports System.IO

    Then heres the function, and how to use it in a button. The HTML source will popup in a msgbox

    VB Code:
    1. Public Function getpage(ByVal url As String) As String
    2.  
    3.         Dim wreq As WebRequest 'request obj
    4.         Dim wres As WebResponse 'response obj
    5.         Dim sr As StreamReader 'streamreader
    6.         Dim content As String 'html source
    7.  
    8.         wreq = HttpWebRequest.Create(url) 'request the page
    9.         wres = wreq.GetResponse() 'store the response
    10.         sr = New StreamReader(wres.GetResponseStream()) 'get the stream from the response
    11.         content = sr.ReadToEnd() 'store the entire html stream in the content var
    12.         sr.Close() 'close the stream
    13.  
    14.         Return content 'return the html
    15.  
    16.     End Function
    17.  
    18.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    19.         MessageBox.Show(getpage("http://www.google.com"))
    20.     End Sub
    Chris

  4. #4
    Junior Member
    Join Date
    Dec 2006
    Posts
    18

    Re: Quickest way to get a page/Most control

    Is there other classes like the HTTPWebRequest that do some of the other things the winsock control did in the past?

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Quickest way to get a page/Most control

    Quote Originally Posted by mjwest10
    Is there other classes like the HTTPWebRequest that do some of the other things the winsock control did in the past?
    Yes, depends what you want to do. Theres classes for almost everything. You can connect a raw socket or accept raw connections in VB.NET using the System.Net namespace, for example the TCPClient class and TCPListener
    Chris

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    7

    Re: Quickest way to get a page/Most control

    WebRequest and WebResponse are working pretty nicely, about .2 seconds per page. Thanks!

  7. #7
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Re: Quickest way to get a page/Most control

    i use a very simple code to get the web to a text box.

    VB Code:
    1. Private Sub Command1_Click()
    2.  Dim strData As String
    3.  strData = Inet1.OpenURL("http://www.yourwebsite.com/")
    4.  DoEvents
    5.  txtSource.Text = Replace(Replace(strData, vbCr, vbCrLf), vbLf, vbCrLf)
    6.  
    7.  'txtSource.Text is where the source will be shown after it grab from the site.
    8.  'but make sure txtSource have multiline option selected or else you wont see anything
    9. End Sub

  8. #8
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Quickest way to get a page/Most control

    Quote Originally Posted by Nerd-Man
    i use a very simple code to get the web to a text box.

    VB Code:
    1. Private Sub Command1_Click()
    2.  Dim strData As String
    3.  strData = Inet1.OpenURL("http://www.yourwebsite.com/")
    4.  DoEvents
    5.  txtSource.Text = Replace(Replace(strData, vbCr, vbCrLf), vbLf, vbCrLf)
    6.  
    7.  'txtSource.Text is where the source will be shown after it grab from the site.
    8.  'but make sure txtSource have multiline option selected or else you wont see anything
    9. End Sub
    Nerdman this thread is for VB.NET not VB6, your code is VB6
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width