Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Get URL of image source
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Mar 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Get URL of image source

    Hi. I am trying to pull the URL of a certain image when using the ie.getelementby... method.

    Using the following I can access the url I need but it's surrounded by html code that is proving difficult for me to seperate out:

    test = ie.document.getElementById("recaptcha_image").InnerHtml

    this is what debug.print test shows me:


    reCAPTCHA challenge image"http://www.google.com/recaptcha/api/image?c=03AHJ_VuseNxC9vqebkGvR3AamjyyeAaPVUSkJcCkZ6fVvhQbxIOC8YiIZHV9p6-Ay-09daLWUf3BSIeYIHqczZVIKAhdFR_HnqTlEMUXNga81zlDAIJ2fwwM9qMEgLxkXM568OSGCvuiQn-QVI6Ob7y1RWKXpMEjIMA" width=300 height=57>

    does anyone have any suggestions or a completely different way I should be looking at the image source?


    Just for clarity, I'm pulling an image from a site and pasting it into a specified cell. I already have part 2 working but I have to pass in the necessary url. If I paste in the url from getelementbyid (manually extracting it) the correct image shows up in excel.


    I don't believe im violating any terms of service regarding captcha as im still requiring a person to type in the response.


    thanks in advance!
    Last edited by moberry; Mar 22nd, 2012 at 01:56 PM.

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Get URL of image source

    The URL is the part between double quotes.
    Microsoft MVP - Excel

  3. #3
    Board Regular BiocideJ's Avatar
    Join Date
    Jan 2012
    Location
    Florida, USA
    Posts
    1,733
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get URL of image source

    You should be able to use this to pull out the image URL.
    Code:
    imgURL = Mid(test, InStr(1, test, Chr(34)) + 1, InStr(InStr(1, test, Chr(34)) + 1, test, Chr(34)) - (InStr(1, test, Chr(34)) + 1))
    this pulls everything between the first and second quotation mark [Chr(34)].

  4. #4
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,140
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Get URL of image source

    Use the src attribute/property of the image to get the URL.
    Code:
    test = ie.document.getElementById("recaptcha_image").src
    If posting code please use code tags.

  5. #5
    Board Regular BiocideJ's Avatar
    Join Date
    Jan 2012
    Location
    Florida, USA
    Posts
    1,733
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get URL of image source

    Quote Originally Posted by Norie View Post
    Use the src attribute/property of the image to get the URL.
    Code:
    test = ie.document.getElementById("recaptcha_image").src
    Nice. I don't use the IE objects very often so if this works it is clearly much simpler.

  6. #6
    New Member
    Join Date
    Mar 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get URL of image source

    Quote Originally Posted by Andrew Poulsom View Post
    The URL is the part between double quotes.
    I hope the sarcasm is good hearted...

  7. #7
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,140
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Get URL of image source

    It'll only work if getElementByID returns an image element, or another type of element that has src as a propert, eg video, audio.
    If posting code please use code tags.

  8. #8
    New Member
    Join Date
    Mar 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get URL of image source

    Quote Originally Posted by Norie View Post
    Use the src attribute/property of the image to get the URL.
    Code:
    test = ie.document.getElementById("recaptcha_image").src
    Yeah i tried .src but I get:

    "Run-time error '438':

    Object doesn't support this property of method"



    i dont get the above error with .innerhtml

  9. #9
    New Member
    Join Date
    Mar 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Get URL of image source

    Quote Originally Posted by Norie View Post
    It'll only work if getElementByID returns an image element, or another type of element that has src as a propert, eg video, audio.
    so the problem is that I am using the wrong definition for the "test" variable or is it that if I set the image as an element I won't be able to extract the source url?





    I tried messing around with some find and replace type of stuff to grab the url from the test string that I had but its got quotations in it that was screwing things up.


    thanks for the help

  10. #10
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,140
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Get URL of image source

    Does ie.document.getElementById("recaptcha_image") return an image?

    What's the entire HTML for the node?

    You can post it here if you enclose it in [HTML][/HTML] tabs.
    Last edited by Norie; Mar 22nd, 2012 at 02:34 PM.
    If posting code please use code tags.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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