Results 1 to 22 of 22

Thread: HTML download problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    HTML download problem

    I some code that is supposed to download a whole webpage but it seems to only download the first portion of it, maybe 50%. Why is that? Or does MsgBox only display a limited amount of characters?

    VB Code:
    1. Dim Data as String
    2. Dim strKeywords  as String
    3. strKeywords="Dog food"
    4. Data = Inet1.OpenURL("http://mystite.com/cgi-bin/script/script.cgi/?skin=jonclean1&length=10&keywords=" & strKeywords & "'")
    5. MsgBox Data

    Webpage html:

    Code:
          <span class="class1">
          <p>  <a href="http://www.5stardog.com/">5 Star Dog</a>
            Online resource for dog owners that includes information on pet selection, training, breeders, and food along with breed descriptions, pictures, forums, and links.<br>
             <a href="http://www.purina.com/intl/default.asp">Nestlé Purina PetCare Company</a>
            International manufacturer and distributor of food, treats and litter for dogs and cats. Portal to specific national sites.<br>
             <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0439110165?v=glance">Amazon.com: Dog Food: Books: Joost Elffers,Saxton Freymann</a>
            ... Dog Food (Hardcover) by Joost Elffers, Saxton Freymann "Good dog ... a list of ingredients included on the back cover, Dog Food is a captivating and humorous feast for the eyes ...<br>
             <a href="http://www.therustydog.com/">The Rusty Dog</a>
            Carries natural foods as well as pet furniture and gifts.<br>
             <a href="http://www.vegetariandogs.com/">Vegetarian Dog Food</a>
            This beautiful and easy to use site is dedicated to vegetarian dog information. Find out where to purchase commercial vegetarian dog food or how you can learn to make your own. ... If you would rather purchase a commercial vegetarian dog food (see resources), you will gain confidence and the ... 90%."3 Overall, there are no major obstacles to vegetarian dog food ...<br>
             <a href="http://www.vetref.net/">VetRef.net</a>
            Resources for owners and veterinarians; includes articles on pet health, whole foods diets, electron microscopy, anti-roaming dog downloads, and links to other sites of veterinary interest.<br>
             <a href="http://en.wikipedia.org/wiki/Dog_food">Wikipedia: Dog food</a>
            Dog food is plant or animal material intended for consumption by dogs or other canids. Special dog foods given as a reward, and not as a staple, are known as dog treats. ... Some people make their own dog food or feed their dogs meals made from ingredients ...<br>
             <a href="http://www.ecopet.com.au/">Ecopet</a>
            Formulating natural food for dogs and cats.<br>
             <a href="http://www.dogchow.com/">Purina Dog Chow</a>
            Get information on nutrition for your best friend and even create a homepage for your dog.<br>
             <a href="http://www.yorkie.org/supplies/pet_food.html">Rhapsody Yorkshire Terriers: Dog Food and Treats</a>
            Offers treat and food recipes targeted for Yorkshire Terriers.<br>
               
            </p>
    	  </span>

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    Try

    Debug.Print Data

    then look in your immediate (debug) window... see if its all there.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    Ok, tried that and all I got was this...

    Code:
          <span class="class1">
          <p>  <a href="http://www.5stardog.com/">5 Star Dog</a>
            Online resource for dog owners that includes information on pet selection, training, breeders, and food along with breed descriptions, pictures, forums, and links.<br>
             <a href="http://www.purina.com/intl/default.asp">Nestlé Purina PetCare Company</a>
            International manufacturer and distributor of food, treats and litter for dogs and cats. Portal to specific national sites.<br>
             <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0439110165?v=glance">Amazon.com: Dog Food: Books: Joost Elffers,Saxton Freymann</a>
            ... Dog Food (Hardcover) by Joost Elffers, Saxton Freymann "Good dog ... a list of ingredients included on the back cover, Dog Food is a captivating and humorous feast for the eyes ...<br>
             <a href="http://www.therustydog.com/">The Rusty Dog</a>
            Carries natural foods as well as pet furniture and gifts.<br>
             <a href="http://www.vegetariandogs.com/">Vegetarian Dog Food</a>
            This beautiful and easy to use site is dedicated to vegetarian dog information. Find out where to purchase commercial vegetarian dog food or how you can learn to make your own. ... If you would rather purchase a commerc

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: HTML download problem

    inet and webbrowser are very similar, which is why I am posting this. When I downloaded websites with webbrowser and grab the source HTML from it, I would find that the original source would be missing certain elements that should be there. Now someone ELSE will have to help you here, but try setting HEADER data to be sent when you request the URL. Header data would include shizzle like the browser you're using, the system you're on and all-sorts like that (even cookie data if you were using a site that needed it)...without the browser information, some sites would return partial data...hope that helps :-)

    Edit: In fact, I had one site that REFUSED flat out to let me send get data (form stuff) without putting valid header data in to tell it referer and all that :-)

  5. #5
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: HTML download problem

    Debug.Print sometimes doesn't print all data. If you want to see all the data in the string, print it to a file & then open the file manually (use 'Open "C:\debug.txt" For Output As #1...)
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    A bit later in my code it updates a mySQL database anyway so I can check. Is webbrowser better to use than inet?

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    Quote Originally Posted by shirazamod
    Debug.Print sometimes doesn't print all data. If you want to see all the data in the string, print it to a file & then open the file manually (use 'Open "C:\debug.txt" For Output As #1...)

    Debug.print doesnt print all the data??
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: HTML download problem

    Quote Originally Posted by Jon12345
    Is webbrowser better to use than inet?
    The problem with webbrowser is that (unless you write in code to stop it) it loads everything on a page...images...background music (if you have it)...everything...Inet just grabs the HTML and that's it, and Inet is a hell of a lot faster in that respect because of it. However, it's a lot more work to get it working if you need specialised stuff like cookies or header info :-)

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    whats the real URL???.. using Webbrowser & HTML object you can pull any part of the page...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: HTML download problem

    VB Code:
    1. Dim Data As String
    2. Data = Inet1.OpenURL("http://www.vbforums.com")
    3. While Inet1.StillExecuting = True
    4.     DoEvents
    5. Wend
    6. MsgBox Data
    7. Debug.Print Data
    i used vbforums as example (couldn't reach your given page). When the messagebox appears, a big part of the text is missing. if you look at debug now, it has the full code.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    Since there seems to be a bug in the inet component, I would like to try webbrowser. So I have the following code:

    VB Code:
    1. Dim hDoc
    2.     Dim strKeywords as String
    3.     Dim HTMLSource As String
    4.     strKeywords = "dog%20food"
    5.     WebBrowser1.Navigate ("http://mysite.com/cgi-bin/script/script.cgi/?skin=jonclean1&length=10&keywords=" & strKeywords & "'")
    6.     hDoc = WebBrowser1.Document
    7.     HTMLSource = hDoc.body.innerhtml

    But when I run this I get this error:

    "Object variable or With block variable not set"

    What is wrong with the code?

  12. #12
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     strKeywords = "dog%20food"
    4.     WebBrowser1.Navigate "http://mysite.com/cgi-bin/script/script.cgi/?skin=jonclean1&length=10&keywords=" & strKeywords & "'"
    5.  
    6. End Sub
    7.  
    8.  
    9. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    10.     If (pDisp Is WebBrowser1.Application) Then
    11.         Dim HTMLSource As String
    12.         HTMLSource = WebBrowser.Document.documentElement.innerHTML
    13.        
    14.     End If
    15. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    Static, I am a bit confused on how I would use your code. Currently, my code runs if someone clicks on a command button. It then cycles through a list of urls.

  14. #14
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    add the webbrowser control

    then paste in the document complete code.

    put the navigate to behind your button click

    I cant test it because that url is no good
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    To make things simpler, I am just using www.yahoo.com

    So, my code is as follows:

    VB Code:
    1. Private Sub Command1_Click()
    2. strKeywords = "dog%20food"
    3. WebBrowser1.Navigate "www.yahoo.com"
    4. End Sub
    5.  
    6. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    7.     If (pDisp Is WebBrowser1.Application) Then
    8.         Dim HTMLSource As String
    9.         HTMLSource = WebBrowser.Document.documentElement.innerHTML
    10.        
    11.     End If
    12. End Sub

    When I click the button, it loads Yahoo into the WebBrowser control and then I get the error Object required. Run-time error '424'. The following line of code is then highlighted:

    VB Code:
    1. HTMLSource = WebBrowser.Document.documentElement.innerHTML

  16. #16
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    oops WebBrowser

    WebBrowser1
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    No error message now. But I can't see how the WebBrowser1_DocumentComplete subroutine is called. From what I can see, you click the button and it just runs the two lines of code.

    What am I missing here?

  18. #18
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: HTML download problem

    When the website has been fully loaded (including images etc) it will call the DocumentComplete event
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  19. #19
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    you are also not displaying it anywhere

    add

    VB Code:
    1. Debug.Print HTMLSource
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    What I am getting confused about is that I want to run a loop with changing urls. This will happen when I click the command button. But it seems that "Private Sub Command1_Click()" subroutine loses control and another subroutine is triggered.

    Therefore, I cannot loop through the code for changing urls, correct?

  21. #21
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HTML download problem

    Yes.. I would do it like this
    (assuming u have URLs listed in Listbox (List1))

    VB Code:
    1. Dim lIndex As Integer
    2. Private Sub Command1_Click()
    3.     lIndex = 0
    4.     LoopURLS
    5. End Sub
    6.  
    7. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    8.     If (pDisp Is WebBrowser1.Application) Then
    9.         Debug.Print WebBrowser.Document.documentElement.innerHTML
    10.         LoopURLS
    11.     End If
    12. End Sub
    13.  
    14. Private Sub LoopURLS()
    15.     Dim tmp As String
    16.     If lIndex >= List1.ListCount Then Exit Sub
    17.     tmp = List1.List(lIndex)
    18.     WebBrowser1.Navigate tmp
    19.     lIndex = lIndex + 1
    20. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: HTML download problem

    Thanks Static! I will give that a whirl.

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