Trying to get for searching lattitude and longitude of places using vba from a web page. find button clicking...












0














When executing this code it is filling the required text box on the website but pressing the find button gives the output 'not found' in the message box.



Subsequently, if i manually just click in the text box on the filled value and then click the find button, it shows the desired result.



How can I make this work?



Public Sub experiment()

Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.navigate "https://www.latlong.net/"

Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE

Dim doc As HTMLDocument
Set doc = ie.document
Dim inputElement As HTMLInputElement

Set inputElement = doc.getElementsByClassName("width70")(0)
inputElement.Value = "Delhi Airport, India"

ie.Visible = True

doc.getElementById("btnfind").Click


Do

DoEvents

Loop Until ie.readyState = READYSTATE_COMPLETE

End Sub









share|improve this question





























    0














    When executing this code it is filling the required text box on the website but pressing the find button gives the output 'not found' in the message box.



    Subsequently, if i manually just click in the text box on the filled value and then click the find button, it shows the desired result.



    How can I make this work?



    Public Sub experiment()

    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.navigate "https://www.latlong.net/"

    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE

    Dim doc As HTMLDocument
    Set doc = ie.document
    Dim inputElement As HTMLInputElement

    Set inputElement = doc.getElementsByClassName("width70")(0)
    inputElement.Value = "Delhi Airport, India"

    ie.Visible = True

    doc.getElementById("btnfind").Click


    Do

    DoEvents

    Loop Until ie.readyState = READYSTATE_COMPLETE

    End Sub









    share|improve this question



























      0












      0








      0


      1





      When executing this code it is filling the required text box on the website but pressing the find button gives the output 'not found' in the message box.



      Subsequently, if i manually just click in the text box on the filled value and then click the find button, it shows the desired result.



      How can I make this work?



      Public Sub experiment()

      Dim ie As InternetExplorer
      Set ie = New InternetExplorer
      ie.navigate "https://www.latlong.net/"

      Do
      DoEvents
      Loop Until ie.readyState = READYSTATE_COMPLETE

      Dim doc As HTMLDocument
      Set doc = ie.document
      Dim inputElement As HTMLInputElement

      Set inputElement = doc.getElementsByClassName("width70")(0)
      inputElement.Value = "Delhi Airport, India"

      ie.Visible = True

      doc.getElementById("btnfind").Click


      Do

      DoEvents

      Loop Until ie.readyState = READYSTATE_COMPLETE

      End Sub









      share|improve this question















      When executing this code it is filling the required text box on the website but pressing the find button gives the output 'not found' in the message box.



      Subsequently, if i manually just click in the text box on the filled value and then click the find button, it shows the desired result.



      How can I make this work?



      Public Sub experiment()

      Dim ie As InternetExplorer
      Set ie = New InternetExplorer
      ie.navigate "https://www.latlong.net/"

      Do
      DoEvents
      Loop Until ie.readyState = READYSTATE_COMPLETE

      Dim doc As HTMLDocument
      Set doc = ie.document
      Dim inputElement As HTMLInputElement

      Set inputElement = doc.getElementsByClassName("width70")(0)
      inputElement.Value = "Delhi Airport, India"

      ie.Visible = True

      doc.getElementById("btnfind").Click


      Do

      DoEvents

      Loop Until ie.readyState = READYSTATE_COMPLETE

      End Sub






      excel vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 14:31









      Cindy Meister

      14.3k102134




      14.3k102134










      asked Nov 23 '18 at 10:53









      YauravYaurav

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Rather than IE automation and interacting with the page as a user would, the code below should emulate the request triggered by the 'Find' button on the page, but you need to assign a value to placeName in the code (currently it is "Delhi Airport, India").



          If you are interested in only the co-ordinates (and no other information on the rest of the page), then this approach might be okay for you.



          You'll need to add a reference (Tools > References > Scroll down and tick Microsoft XML, v6.0 > OK) before trying to run the code.



          Option Explicit

          Private Sub Experiment()
          Dim placeName As String
          placeName = "Delhi Airport, India"

          Dim WebClient As MSXML2.ServerXMLHTTP60
          Set WebClient = New MSXML2.ServerXMLHTTP60

          With WebClient
          .Open "POST", "https://www.latlong.net/_spm4.php", True
          .setRequestHeader ":authority", "www.latlong.net"
          .setRequestHeader ":method", "POST"
          .setRequestHeader ":path", "/_spm4.php"
          .setRequestHeader ":scheme", "https"
          .setRequestHeader "accept", "*/*"
          .setRequestHeader "content-type", "application/x-www-form-urlencoded"
          .setRequestHeader "origin", "https://www.latlong.net"
          .setRequestHeader "referer", "https://www.latlong.net/"
          .setRequestHeader "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
          .setRequestHeader "x-requested-with", "XMLHttpRequest"

          Dim bodyToSend As String
          bodyToSend = "c1=" & Application.EncodeURL(placeName) & "&action=gpcm&cp="

          .send bodyToSend
          .waitForResponse

          MsgBox ("Server's response to the request for Place Name '" & placeName & "' is " & _
          vbNewLine & vbNewLine & .responseText)
          End With
          End Sub


          You can access the server's response (which will contain the co-ordinates if the request was successful) with WebClient.responseText (or just .responseText inside the With statement) -- and then do what you need to with it.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445302%2ftrying-to-get-for-searching-lattitude-and-longitude-of-places-using-vba-from-a-w%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Rather than IE automation and interacting with the page as a user would, the code below should emulate the request triggered by the 'Find' button on the page, but you need to assign a value to placeName in the code (currently it is "Delhi Airport, India").



            If you are interested in only the co-ordinates (and no other information on the rest of the page), then this approach might be okay for you.



            You'll need to add a reference (Tools > References > Scroll down and tick Microsoft XML, v6.0 > OK) before trying to run the code.



            Option Explicit

            Private Sub Experiment()
            Dim placeName As String
            placeName = "Delhi Airport, India"

            Dim WebClient As MSXML2.ServerXMLHTTP60
            Set WebClient = New MSXML2.ServerXMLHTTP60

            With WebClient
            .Open "POST", "https://www.latlong.net/_spm4.php", True
            .setRequestHeader ":authority", "www.latlong.net"
            .setRequestHeader ":method", "POST"
            .setRequestHeader ":path", "/_spm4.php"
            .setRequestHeader ":scheme", "https"
            .setRequestHeader "accept", "*/*"
            .setRequestHeader "content-type", "application/x-www-form-urlencoded"
            .setRequestHeader "origin", "https://www.latlong.net"
            .setRequestHeader "referer", "https://www.latlong.net/"
            .setRequestHeader "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
            .setRequestHeader "x-requested-with", "XMLHttpRequest"

            Dim bodyToSend As String
            bodyToSend = "c1=" & Application.EncodeURL(placeName) & "&action=gpcm&cp="

            .send bodyToSend
            .waitForResponse

            MsgBox ("Server's response to the request for Place Name '" & placeName & "' is " & _
            vbNewLine & vbNewLine & .responseText)
            End With
            End Sub


            You can access the server's response (which will contain the co-ordinates if the request was successful) with WebClient.responseText (or just .responseText inside the With statement) -- and then do what you need to with it.






            share|improve this answer


























              0














              Rather than IE automation and interacting with the page as a user would, the code below should emulate the request triggered by the 'Find' button on the page, but you need to assign a value to placeName in the code (currently it is "Delhi Airport, India").



              If you are interested in only the co-ordinates (and no other information on the rest of the page), then this approach might be okay for you.



              You'll need to add a reference (Tools > References > Scroll down and tick Microsoft XML, v6.0 > OK) before trying to run the code.



              Option Explicit

              Private Sub Experiment()
              Dim placeName As String
              placeName = "Delhi Airport, India"

              Dim WebClient As MSXML2.ServerXMLHTTP60
              Set WebClient = New MSXML2.ServerXMLHTTP60

              With WebClient
              .Open "POST", "https://www.latlong.net/_spm4.php", True
              .setRequestHeader ":authority", "www.latlong.net"
              .setRequestHeader ":method", "POST"
              .setRequestHeader ":path", "/_spm4.php"
              .setRequestHeader ":scheme", "https"
              .setRequestHeader "accept", "*/*"
              .setRequestHeader "content-type", "application/x-www-form-urlencoded"
              .setRequestHeader "origin", "https://www.latlong.net"
              .setRequestHeader "referer", "https://www.latlong.net/"
              .setRequestHeader "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
              .setRequestHeader "x-requested-with", "XMLHttpRequest"

              Dim bodyToSend As String
              bodyToSend = "c1=" & Application.EncodeURL(placeName) & "&action=gpcm&cp="

              .send bodyToSend
              .waitForResponse

              MsgBox ("Server's response to the request for Place Name '" & placeName & "' is " & _
              vbNewLine & vbNewLine & .responseText)
              End With
              End Sub


              You can access the server's response (which will contain the co-ordinates if the request was successful) with WebClient.responseText (or just .responseText inside the With statement) -- and then do what you need to with it.






              share|improve this answer
























                0












                0








                0






                Rather than IE automation and interacting with the page as a user would, the code below should emulate the request triggered by the 'Find' button on the page, but you need to assign a value to placeName in the code (currently it is "Delhi Airport, India").



                If you are interested in only the co-ordinates (and no other information on the rest of the page), then this approach might be okay for you.



                You'll need to add a reference (Tools > References > Scroll down and tick Microsoft XML, v6.0 > OK) before trying to run the code.



                Option Explicit

                Private Sub Experiment()
                Dim placeName As String
                placeName = "Delhi Airport, India"

                Dim WebClient As MSXML2.ServerXMLHTTP60
                Set WebClient = New MSXML2.ServerXMLHTTP60

                With WebClient
                .Open "POST", "https://www.latlong.net/_spm4.php", True
                .setRequestHeader ":authority", "www.latlong.net"
                .setRequestHeader ":method", "POST"
                .setRequestHeader ":path", "/_spm4.php"
                .setRequestHeader ":scheme", "https"
                .setRequestHeader "accept", "*/*"
                .setRequestHeader "content-type", "application/x-www-form-urlencoded"
                .setRequestHeader "origin", "https://www.latlong.net"
                .setRequestHeader "referer", "https://www.latlong.net/"
                .setRequestHeader "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
                .setRequestHeader "x-requested-with", "XMLHttpRequest"

                Dim bodyToSend As String
                bodyToSend = "c1=" & Application.EncodeURL(placeName) & "&action=gpcm&cp="

                .send bodyToSend
                .waitForResponse

                MsgBox ("Server's response to the request for Place Name '" & placeName & "' is " & _
                vbNewLine & vbNewLine & .responseText)
                End With
                End Sub


                You can access the server's response (which will contain the co-ordinates if the request was successful) with WebClient.responseText (or just .responseText inside the With statement) -- and then do what you need to with it.






                share|improve this answer












                Rather than IE automation and interacting with the page as a user would, the code below should emulate the request triggered by the 'Find' button on the page, but you need to assign a value to placeName in the code (currently it is "Delhi Airport, India").



                If you are interested in only the co-ordinates (and no other information on the rest of the page), then this approach might be okay for you.



                You'll need to add a reference (Tools > References > Scroll down and tick Microsoft XML, v6.0 > OK) before trying to run the code.



                Option Explicit

                Private Sub Experiment()
                Dim placeName As String
                placeName = "Delhi Airport, India"

                Dim WebClient As MSXML2.ServerXMLHTTP60
                Set WebClient = New MSXML2.ServerXMLHTTP60

                With WebClient
                .Open "POST", "https://www.latlong.net/_spm4.php", True
                .setRequestHeader ":authority", "www.latlong.net"
                .setRequestHeader ":method", "POST"
                .setRequestHeader ":path", "/_spm4.php"
                .setRequestHeader ":scheme", "https"
                .setRequestHeader "accept", "*/*"
                .setRequestHeader "content-type", "application/x-www-form-urlencoded"
                .setRequestHeader "origin", "https://www.latlong.net"
                .setRequestHeader "referer", "https://www.latlong.net/"
                .setRequestHeader "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
                .setRequestHeader "x-requested-with", "XMLHttpRequest"

                Dim bodyToSend As String
                bodyToSend = "c1=" & Application.EncodeURL(placeName) & "&action=gpcm&cp="

                .send bodyToSend
                .waitForResponse

                MsgBox ("Server's response to the request for Place Name '" & placeName & "' is " & _
                vbNewLine & vbNewLine & .responseText)
                End With
                End Sub


                You can access the server's response (which will contain the co-ordinates if the request was successful) with WebClient.responseText (or just .responseText inside the With statement) -- and then do what you need to with it.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 12:49









                chillinchillin

                1,354134




                1,354134






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445302%2ftrying-to-get-for-searching-lattitude-and-longitude-of-places-using-vba-from-a-w%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    Alexandru Averescu

                    Trompette piccolo