Results 1 to 5 of 5

Thread: Grabbing text/images from webpage using Vb/VB.net

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    16

    Grabbing text/images from webpage using Vb/VB.net

    Does anybody know what is the api use for grabbing contents from webpages in vb/vb.net?

    can you gimme a small example.

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Grabbing text/images from webpage using Vb/VB.net

    I only know that if you add a webBrowser control to your form, load a page and then run this (and other variations can get you other text) you can get all the main text:

    vb Code:
    1. Dim myText As String = Me.WebBrowser1.Document.Body.InnerText

    You can look at getting the inner html for example and find the links to images and maybe get the images that way and download them but apart from that i don't know about images.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Grabbing text/images from webpage using Vb/VB.net

    Not used this specific one but there are various methods associated with the document allowing access to and setting specific parts of it, including an images collection. From a quick look think you want the outer html property, this is string containing the src="imagename" bit that you want, eg:

    <img alt="Close this page" src="images\butt_stop.gif" border=2 width=100%>

    Parse string to get name from the src= bit and put it on a control using Image.FromFile.

    To get 1st image say, bung a webbrowser on then summit like:

    webbrowser1.Navigate(New System.Uri(FileName))
    str = WebBrowser1.Document.Images(0).OuterHTML
    ....parse string for src name into imagename here
    control.Image = System.Drawing.Image.FromFile(Imagename)
    Last edited by xoggoth; Jun 27th, 2007 at 07:25 AM.

  4. #4
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Grabbing text/images from webpage using Vb/VB.net

    Or quick and dirty to get text without tags use clipboard

    WebBrowser1.Document.ExecCommand("SelectAll", False, Nothing)
    WebBrowser1.Document.ExecCommand("Copy", False, Nothing)
    WebBrowser1.Document.ExecCommand("Unselect", False, Nothing)

    Something or other to paste text into textbox here - not used it.

  5. #5
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    Re: Grabbing text/images from webpage using Vb/VB.net

    yeah, if you have a webbrowser control on your form. If not use the webclient class to post, get, and grab images from a page.

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