Get Captcha Image from Web Browser control without using SRC












0















I know this question might sound familiar and there are plenty of posts out there on google with the same title BUT trust me this is different.



Editor : VS2008 (cannot upgrade it due to some technical difficulties)



Question



How to get Captcha Image from a Web Browser without using SRC?



Why wouldn't you use SRC?



Here is the site from which i am trying to get my Captcha Image
https://services.gst.gov.in/services/login

(The capta image appears once you type anything in User Name)



Now if you right click on the Captcha Image and go to inspect element you will see that the SRC of the captcha is:-



enter image description here



https://services.gst.gov.in/services/captcha?rnd=0.5313315062651027



and whenever you try to go to that link it will give you a captcha that is different from the previous one. That is why i cant use the below code because it shows different captcha than the one showing in the WebBrowser right now.



HtmlElement element = webBrowser1.Document.GetElementById("imgCaptcha");
string src = element.GetAttribute("src");
pictureBox1.Load(element.GetAttribute("src"));









share|improve this question





























    0















    I know this question might sound familiar and there are plenty of posts out there on google with the same title BUT trust me this is different.



    Editor : VS2008 (cannot upgrade it due to some technical difficulties)



    Question



    How to get Captcha Image from a Web Browser without using SRC?



    Why wouldn't you use SRC?



    Here is the site from which i am trying to get my Captcha Image
    https://services.gst.gov.in/services/login

    (The capta image appears once you type anything in User Name)



    Now if you right click on the Captcha Image and go to inspect element you will see that the SRC of the captcha is:-



    enter image description here



    https://services.gst.gov.in/services/captcha?rnd=0.5313315062651027



    and whenever you try to go to that link it will give you a captcha that is different from the previous one. That is why i cant use the below code because it shows different captcha than the one showing in the WebBrowser right now.



    HtmlElement element = webBrowser1.Document.GetElementById("imgCaptcha");
    string src = element.GetAttribute("src");
    pictureBox1.Load(element.GetAttribute("src"));









    share|improve this question



























      0












      0








      0








      I know this question might sound familiar and there are plenty of posts out there on google with the same title BUT trust me this is different.



      Editor : VS2008 (cannot upgrade it due to some technical difficulties)



      Question



      How to get Captcha Image from a Web Browser without using SRC?



      Why wouldn't you use SRC?



      Here is the site from which i am trying to get my Captcha Image
      https://services.gst.gov.in/services/login

      (The capta image appears once you type anything in User Name)



      Now if you right click on the Captcha Image and go to inspect element you will see that the SRC of the captcha is:-



      enter image description here



      https://services.gst.gov.in/services/captcha?rnd=0.5313315062651027



      and whenever you try to go to that link it will give you a captcha that is different from the previous one. That is why i cant use the below code because it shows different captcha than the one showing in the WebBrowser right now.



      HtmlElement element = webBrowser1.Document.GetElementById("imgCaptcha");
      string src = element.GetAttribute("src");
      pictureBox1.Load(element.GetAttribute("src"));









      share|improve this question
















      I know this question might sound familiar and there are plenty of posts out there on google with the same title BUT trust me this is different.



      Editor : VS2008 (cannot upgrade it due to some technical difficulties)



      Question



      How to get Captcha Image from a Web Browser without using SRC?



      Why wouldn't you use SRC?



      Here is the site from which i am trying to get my Captcha Image
      https://services.gst.gov.in/services/login

      (The capta image appears once you type anything in User Name)



      Now if you right click on the Captcha Image and go to inspect element you will see that the SRC of the captcha is:-



      enter image description here



      https://services.gst.gov.in/services/captcha?rnd=0.5313315062651027



      and whenever you try to go to that link it will give you a captcha that is different from the previous one. That is why i cant use the below code because it shows different captcha than the one showing in the WebBrowser right now.



      HtmlElement element = webBrowser1.Document.GetElementById("imgCaptcha");
      string src = element.GetAttribute("src");
      pictureBox1.Load(element.GetAttribute("src"));






      c# .net winforms webbrowser-control captcha






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 31 '18 at 18:14









      Reza Aghaei

      66.8k856167




      66.8k856167










      asked Aug 9 '18 at 4:03









      Agent_SpockAgent_Spock

      4171527




      4171527
























          1 Answer
          1






          active

          oldest

          votes


















          1





          +50









          You can use createControlRange to create a controlRange of non-text elements. Then find the image tag, for example by using id, then add the image tag to the control range and call it's execCommand method to execute Copy command, and finally, get the image from clipboard:



          .NET 3.5



          Add a reference to MSHTML. You can find it by Microsoft HTML Object Library under COM references and then add using mshtml;. Then:



          IHTMLElement2 body = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
          IHTMLControlRange controlRange = (IHTMLControlRange)body.createControlRange();
          IHTMLControlElement element = (IHTMLControlElement)webBrowser1.Document
          .GetElementById("imgCaptcha").DomElement;
          controlRange.add(element);
          controlRange.execCommand("Copy", false, null);
          pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


          .NET >= 4.0



          You don't need to add a reference, you can take advantage of dynamic:



          dynamic body = webBrowser1.Document.Body.DomElement;
          dynamic controlRange = body.createControlRange();
          dynamic element = webBrowser1.Document.GetElementById("imgCaptcha").DomElement;
          controlRange.add(element);
          controlRange.execCommand("Copy", false, null);
          pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


          Note:




          • Run the code when the document is completed, for example in DocumentCompleted event.


          • Also you may want to add null checking to the code.


          • I used above code to get the google logo from https://www.google.com by id hplogo.


          • I also tested above code, by browsing https://demos.captcha.com/demos/features/captcha-demo.aspx and finding the captcah image by c_captchademo_samplecaptcha_CaptchaImage as id of the captcha image.







          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%2f51758651%2fget-captcha-image-from-web-browser-control-without-using-src%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









            1





            +50









            You can use createControlRange to create a controlRange of non-text elements. Then find the image tag, for example by using id, then add the image tag to the control range and call it's execCommand method to execute Copy command, and finally, get the image from clipboard:



            .NET 3.5



            Add a reference to MSHTML. You can find it by Microsoft HTML Object Library under COM references and then add using mshtml;. Then:



            IHTMLElement2 body = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
            IHTMLControlRange controlRange = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement element = (IHTMLControlElement)webBrowser1.Document
            .GetElementById("imgCaptcha").DomElement;
            controlRange.add(element);
            controlRange.execCommand("Copy", false, null);
            pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


            .NET >= 4.0



            You don't need to add a reference, you can take advantage of dynamic:



            dynamic body = webBrowser1.Document.Body.DomElement;
            dynamic controlRange = body.createControlRange();
            dynamic element = webBrowser1.Document.GetElementById("imgCaptcha").DomElement;
            controlRange.add(element);
            controlRange.execCommand("Copy", false, null);
            pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


            Note:




            • Run the code when the document is completed, for example in DocumentCompleted event.


            • Also you may want to add null checking to the code.


            • I used above code to get the google logo from https://www.google.com by id hplogo.


            • I also tested above code, by browsing https://demos.captcha.com/demos/features/captcha-demo.aspx and finding the captcah image by c_captchademo_samplecaptcha_CaptchaImage as id of the captcha image.







            share|improve this answer






























              1





              +50









              You can use createControlRange to create a controlRange of non-text elements. Then find the image tag, for example by using id, then add the image tag to the control range and call it's execCommand method to execute Copy command, and finally, get the image from clipboard:



              .NET 3.5



              Add a reference to MSHTML. You can find it by Microsoft HTML Object Library under COM references and then add using mshtml;. Then:



              IHTMLElement2 body = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
              IHTMLControlRange controlRange = (IHTMLControlRange)body.createControlRange();
              IHTMLControlElement element = (IHTMLControlElement)webBrowser1.Document
              .GetElementById("imgCaptcha").DomElement;
              controlRange.add(element);
              controlRange.execCommand("Copy", false, null);
              pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


              .NET >= 4.0



              You don't need to add a reference, you can take advantage of dynamic:



              dynamic body = webBrowser1.Document.Body.DomElement;
              dynamic controlRange = body.createControlRange();
              dynamic element = webBrowser1.Document.GetElementById("imgCaptcha").DomElement;
              controlRange.add(element);
              controlRange.execCommand("Copy", false, null);
              pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


              Note:




              • Run the code when the document is completed, for example in DocumentCompleted event.


              • Also you may want to add null checking to the code.


              • I used above code to get the google logo from https://www.google.com by id hplogo.


              • I also tested above code, by browsing https://demos.captcha.com/demos/features/captcha-demo.aspx and finding the captcah image by c_captchademo_samplecaptcha_CaptchaImage as id of the captcha image.







              share|improve this answer




























                1





                +50







                1





                +50



                1




                +50





                You can use createControlRange to create a controlRange of non-text elements. Then find the image tag, for example by using id, then add the image tag to the control range and call it's execCommand method to execute Copy command, and finally, get the image from clipboard:



                .NET 3.5



                Add a reference to MSHTML. You can find it by Microsoft HTML Object Library under COM references and then add using mshtml;. Then:



                IHTMLElement2 body = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
                IHTMLControlRange controlRange = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement element = (IHTMLControlElement)webBrowser1.Document
                .GetElementById("imgCaptcha").DomElement;
                controlRange.add(element);
                controlRange.execCommand("Copy", false, null);
                pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


                .NET >= 4.0



                You don't need to add a reference, you can take advantage of dynamic:



                dynamic body = webBrowser1.Document.Body.DomElement;
                dynamic controlRange = body.createControlRange();
                dynamic element = webBrowser1.Document.GetElementById("imgCaptcha").DomElement;
                controlRange.add(element);
                controlRange.execCommand("Copy", false, null);
                pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


                Note:




                • Run the code when the document is completed, for example in DocumentCompleted event.


                • Also you may want to add null checking to the code.


                • I used above code to get the google logo from https://www.google.com by id hplogo.


                • I also tested above code, by browsing https://demos.captcha.com/demos/features/captcha-demo.aspx and finding the captcah image by c_captchademo_samplecaptcha_CaptchaImage as id of the captcha image.







                share|improve this answer















                You can use createControlRange to create a controlRange of non-text elements. Then find the image tag, for example by using id, then add the image tag to the control range and call it's execCommand method to execute Copy command, and finally, get the image from clipboard:



                .NET 3.5



                Add a reference to MSHTML. You can find it by Microsoft HTML Object Library under COM references and then add using mshtml;. Then:



                IHTMLElement2 body = (IHTMLElement2)webBrowser1.Document.Body.DomElement;
                IHTMLControlRange controlRange = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement element = (IHTMLControlElement)webBrowser1.Document
                .GetElementById("imgCaptcha").DomElement;
                controlRange.add(element);
                controlRange.execCommand("Copy", false, null);
                pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


                .NET >= 4.0



                You don't need to add a reference, you can take advantage of dynamic:



                dynamic body = webBrowser1.Document.Body.DomElement;
                dynamic controlRange = body.createControlRange();
                dynamic element = webBrowser1.Document.GetElementById("imgCaptcha").DomElement;
                controlRange.add(element);
                controlRange.execCommand("Copy", false, null);
                pictureBox1.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);


                Note:




                • Run the code when the document is completed, for example in DocumentCompleted event.


                • Also you may want to add null checking to the code.


                • I used above code to get the google logo from https://www.google.com by id hplogo.


                • I also tested above code, by browsing https://demos.captcha.com/demos/features/captcha-demo.aspx and finding the captcah image by c_captchademo_samplecaptcha_CaptchaImage as id of the captcha image.








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 21 '18 at 20:35

























                answered Aug 21 '18 at 19:04









                Reza AghaeiReza Aghaei

                66.8k856167




                66.8k856167
































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51758651%2fget-captcha-image-from-web-browser-control-without-using-src%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

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'