dcsimg
Results 1 to 16 of 16

Thread: Locating a image in web browser during runtime

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Locating a image in web browser during runtime

    How would I locate a image in web browser during runtime?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Locating image in webbrowser during runtime?

    How would I do this?

  3. #3
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Locating image in webbrowser during runtime?

    Not sure what exactly you are trying to do. Are you looking for the index of the HTML element, the image URL, the X,Y coordinates? I'm pretty sure you'll get some help if you can give some details to support your question.

    Best of luck.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating image in webbrowser during runtime?

    Quote Originally Posted by ZenDisaster View Post
    Not sure what exactly you are trying to do. Are you looking for the index of the HTML element, the image URL, the X,Y coordinates? I'm pretty sure you'll get some help if you can give some details to support your question.

    Best of luck.
    Im trying to find a picture/image and/or imageurl in a webbrowser on my form.

  5. #5
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Locating image in webbrowser during runtime?

    Code:
    System.Net.WebClient wClient = new System.Net.WebClient();
    string wbPage = wClient.DownloadString("http://www.google.com");
    
    string imgTags;
    //I forget how to do qoutes since I'm not actually testing out this code, though you can do a quick search to figure that out.
    imgTags = wbPage.substring(wbPage.indexOf(@"<img src=""), ....);
    Something along those lines. wbPage contains all the HTML of the page specified, in this case google.com. You can do a substring / search for the img tags within wbPage.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating image in webbrowser during runtime?

    Quote Originally Posted by noahssite View Post
    Code:
    System.Net.WebClient wClient = new System.Net.WebClient();
    string wbPage = wClient.DownloadString("http://www.google.com");
    
    string imgTags;
    //I forget how to do qoutes since I'm not actually testing out this code, though you can do a quick search to figure that out.
    imgTags = wbPage.substring(wbPage.indexOf(@"<img src=""), ....);
    Something along those lines. wbPage contains all the HTML of the page specified, in this case google.com. You can do a substring / search for the img tags within wbPage.
    Is that VB code? I want to find a image from my Webbrowser control and display it in a picturebox

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Locating a image in web browser during runtime?

    How would I locate an image from my webbrowser control during runtime? I want the image to be displayed in a picturebox. Thanks in advanced if you help.

  8. #8
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Locating image in webbrowser during runtime?

    Oh sorry my mistake, here is the vb code converted:

    Code:
    Dim wClient as new System.Net.WebClient
    dim wbPage as string = wClient.DownloadString("http://www.google.com")
    
    dim imgTags as string
    //I forget how to do qoutes since I'm not actually testing out this code, though you can do a quick search to figure that out.
    imgTags = wbPage.substring(wbPage.indexOf("<img src="), ....)

  9. #9
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Locating a image in web browser during runtime?


  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating a image in web browser during runtime?

    Quote Originally Posted by noahssite View Post
    Sorry, I just really needed help
    Using your code
    Code:
     Dim wClient As New System.Net.WebClient
            Dim wbPage As String = wClient.DownloadString("http://www.google.com")
            Dim imgTags As String
    imgTags = wbPage.substring(wbPage.indexOf("<img src="))
    PictureBox1.ImageLocation = imgTags
    I removed that ,.... and now I get (when debugging)
    "StartIndex cannot be less than zero. Parameter name: startIndex"
    Also, How do I change the wClient.DownloadString("http://google.com"), to the URL in the webbrowser control?
    Edit: when I test this on another site, I get no errors, but no picture shows up.
    Last edited by werido; Oct 8th, 2009 at 07:15 PM.

  11. #11
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Locating a image in web browser during runtime?

    As to your second question, wClient.DownloadString(webbrowserControl.Url.ToString()) I am not sure if there are the parenthesis at the end of ToString, I am a bit confused from my C# coding. Also I doubt that the tags a specified will actually be on google. Try "<img" and then you can use a combination of substrings and IndexOfs to get the begining of the image path.

    When I checked the HTML on google this was the main image:
    <img alt="Google" height=110 src="/intl/en_ca/images/logo.gif" width=276 id=logo onload="window.lol&&lol()">
    So <img src= wouldnt work because it doesnt start like that. Though I am not sure why you are getting an error because there is another image that starts with <img src=

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating a image in web browser during runtime?

    Quote Originally Posted by noahssite View Post
    As to your second question, wClient.DownloadString(webbrowserControl.Url.ToString()) I am not sure if there are the parenthesis at the end of ToString, I am a bit confused from my C# coding. Also I doubt that the tags a specified will actually be on google. Try "<img" and then you can use a combination of substrings and IndexOfs to get the begining of the image path.

    When I checked the HTML on google this was the main image:


    So <img src= wouldnt work because it doesnt start like that. Though I am not sure why you are getting an error because there is another image that starts with <img src=
    So if I change <img scr= it will work?

    Edit: I found a test site that only had one Image.
    Code:
            Dim wClient As New System.Net.WebClient
            Dim wbPage As String = wClient.DownloadString(WebBrowser1.Url.ToString)
            Dim imgTags As String
            imgTags = wbPage.Substring(wbPage.IndexOf("<img id="))
            PictureBox1.ImageLocation = imgTags.ToString
    When I use that, there is still no Image

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating a image in web browser during runtime?

    Can someone help me?

  14. #14

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Re: Locating a image in web browser during runtime

    Quote Originally Posted by MartinLiss View Post
    I merged your three duplicate questions into one. Please don't create more than one threaed for the same question.
    Sorry, I just needed help.

    Code:
            Dim wClient As New System.Net.WebClient
            Dim wbPage As String = wClient.DownloadString(WebBrowser1.Url.ToString)
            Dim imgTags As String
            imgTags = wbPage.Substring(wbPage.IndexOf("<img id="))
            PictureBox1.ImageLocation = imgTags.ToString
    When I use that, there is still no Image

  16. #16
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Locating a image in web browser during runtime

    No imgTags won't actually give you the image. It will give the the location of the image. You will need to use another substring/IndexOf to find where the src=".." begins. Then you will need to get the information between quote one and quote two. Ill reply with working code, in a few minutes.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width