Results 1 to 10 of 10

Thread: Innertext the "src" address using MSXML2.xmlHttp

  1. #1
    New Member
    Join Date
    Jul 2015
    Location
    So Paulo
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Innertext the "src" address using MSXML2.xmlHttp

    I’m trying to innertext a specific "src" address using MSXML2.xmlHttp. But, when I try sending the request with xmlhttp I get no error but it also give me nothing in return. How can I solve that?

    Code:
    Sub WebData()
        Dim obj As Object, resp As String
        With CreateObject("MSXML2.xmlHttp")
            .Open "GET", "stURL", False
            .send
            resp = .responseText
        End With
     
        With CreateObject("HTMLFile")
            .write resp
            For Each obj In .all.getElementsByTagName("img")
                If obj.Content Like "src:/*/" Then
                    MsgBox obj.Content
                End If
            Next
        End With
    Last edited by Estevam Guilherme; Apr 17th, 2019 at 09:53 PM.

  2. #2
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,493
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Hi,
    You have to use real URL like "https://www.mrexcel.com/" instead of "stUrl"
    For example like this:
    Code:
    Sub WebData()
       
        Dim s As String, obj As Object, resp As String
       
        With CreateObject("MSXML2.xmlHttp")
            .Open "GET", "https://www.mrexcel.com/", False
            .send
            resp = .responseText
        End With
     
        With CreateObject("HTMLFile") 
            .write resp
            For Each obj In .Body.Document.getElementsByTagName("img")
               s = obj.OuterHTML
               Debug.Print s ' you may parse s for "src=*" here
            Next
        End With
       
    End Sub
    Regards
    Last edited by ZVI; Apr 18th, 2019 at 12:06 AM.
    Vladimir Zakharov
    Microsoft MVP Office Apps & Services

  3. #3
    New Member
    Join Date
    Jul 2015
    Location
    So Paulo
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Hello Mr.!

    in order to reach my goal I used a real url as you mentioned. It almost brings me all "img" addresses...except the one I want. Maybe it's because its location is between a "table".

    [HTML]
    <table summary="Box per effettuare il login a sistema, inserire username e password." style="float: right">
    <caption>Login a sistema</caption>
    <tr>
    <td scope="row">
    <label for="UserName" id="UserNameLabel">Nome Utente (E-mail):</label>
    </td>
    <td>
    <input name="UserName" type="text" maxlength="255" id="UserName" accesskey="l" tabindex="1" title="Nome Utente (E-mail)" class="myInput" style="width:170px;" />
    </td>
    </tr>
    <tr>
    <td scope="row">
    <label for="Password" id="PasswordLabel">Password:</label>
    </td>
    <td>
    <input name="Password" type="password" maxlength="50" id="Password" tabindex="2" title="Password" class="myInput" style="width:170px;" />
    </td>
    </tr>
    <tr>
    <td>
    <label for="loginCaptcha" id="LblCapt">Codice di verifica:</label>
    </td>
    <td scope="row">
    <input name="loginCaptcha" type="text" id="loginCaptcha" tabindex="3" title="Codice di verifica:" />
    <img id="captchaLogin" src="captcha/default.aspx?pos=2&amp;vers=361676769" alt="Codice di verifica" />
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" name="BtnPwdDimenticataL" value="Ho dimenticato la password" id="BtnPwdDimenticataL" tabindex="5" title="Ho dimenticato la password" class="linkButton" />
    </td>
    <td style="text-align: right">
    <input type="submit" name="BtnConfermaL" value="Login" id="BtnConfermaL" tabindex="4" title="Login" class="inputButton" style="width:170px;" />
    </td>
    </tr>
    </table>
    [HTML]
    Last edited by Estevam Guilherme; Apr 18th, 2019 at 01:28 AM.

  4. #4
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,493
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Then you may parse text of the variable resp for "src:/*/", like this:
    Code:
        ' ...
       
        Dim i As Long, j As Long
        i = InStr(resp, "src:/")
        While i > 0
          j = InStr(i + 5, resp, "/")
          If j Then
            s = Mid(resp, i, j - i + 1)
            Debug.Print s
          End If
          i = InStr(j + 1, resp, "src:/")
        Wend
    Last edited by ZVI; Apr 18th, 2019 at 01:40 AM.
    Vladimir Zakharov
    Microsoft MVP Office Apps & Services

  5. #5
    New Member
    Join Date
    Jul 2015
    Location
    So Paulo
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Mr. ZVI

    Thank you very mch for your support, I've been trying this for days.

  6. #6
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,493
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Quote Originally Posted by Estevam Guilherme View Post
    Mr. ZVI

    Thank you very mch for your support, I've been trying this for days.
    Hope you will find the solution.
    sorte!
    Boa sorte!
    Boa sorte!
    Vladimir Zakharov
    Microsoft MVP Office Apps & Services

  7. #7
    New Member
    Join Date
    Jul 2015
    Location
    So Paulo
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    ZVI, today I got this also working, but I'm not able to outerHTML into excel, could you please give me a light.

    [Dim s As String, obj As Object, resp As String

    With CreateObject("HTMLFile")
    .write sResp

    For Each obj In .body.document.getElementsByTagName("img")
    Debug.Print obj.outerHTML
    Next


    End With]
    Last edited by Estevam Guilherme; Apr 18th, 2019 at 03:13 PM.

  8. #8
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,493
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Sure, try this:
    Code:
    Sub WebData()
     
      Dim s As String, obj As Object, resp As String
       
      ' Put content of a web page to the resp string variable
      With CreateObject("MSXML2.xmlHttp")
        .Open "GET", "https://www.mrexcel.com/", False
        .send
        resp = .responseText
      End With
       
      ' Clear A-column
      ActiveSheet.UsedRange.EntireRow.Columns(1).ClearContents
     
      ' Put a title to A1 cell
      Range("A1").Value = "WebData"
       
      ' Write outerHTMLs below the A1 cell
      With CreateObject("HTMLFile")
        .write resp
        For Each obj In .body.document.getElementsByTagName("img")
          s = obj.outerHTML
          Range("A" & Rows.Count).End(xlUp).Offset(1).Value = s
          'Debug.Print s
        Next
      End With
     
    End Sub
    Last edited by ZVI; Apr 18th, 2019 at 04:06 PM.
    Vladimir Zakharov
    Microsoft MVP Office Apps & Services

  9. #9
    New Member
    Join Date
    Jul 2015
    Location
    So Paulo
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Thank you ZVI, everything is working just fine. Im quite ok with IE automation. But Im new with MSXML2.xmlHttp and like the way you work with.

  10. #10
    MrExcel MVP ZVI's Avatar
    Join Date
    Apr 2008
    Location
    Sevastopol
    Posts
    3,493
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Innertext the "src" address using MSXML2.xmlHttp

    Quote Originally Posted by Estevam Guilherme View Post
    Thank you ZVI, everything is working just fine. I’m quite ok with IE automation. But I’m new with MSXML2.xmlHttp and like the way you work with.
    You are welcome, we are all learners here!
    Vladimir Zakharov
    Microsoft MVP Office Apps & Services

Some videos you may like

User Tag List

Tags for this Thread

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
  •