解决方法" /> 解决方法 - 网页学习体会" />

【Jsoup】doc.getElementsByTag("img");无法获得验证码图片解决方法

【Jsoup】doc.getElementsByTag("img");无法获得验证码图片<img/>
<body>里面的元素

<body class="body">

    <div class="headColor">
      <div class="headControl">
        
        <img class="image-abclogo" src="https://mobile.abchina.com/mpay/mobileBank/zh_CN/EBusinessModule/image/abclogo.png"></img>
        
      </div>
    </div>

    <div class="container">
        <br />
        <h5 class="form-signin-heading">&#x519c;&#x884c;&#x7f51;&#x4e0a;K&#x7801;&#x652f;&#x4ed8;&#xff1a;<br /></h5>
        <form method="post" action="/mpay/KCodePaymentCheckAct.ebf">

        <label for="inputPassword" class="sr-only">&#x519c;&#x884c;&#x5361;&#x53f7;&#xff1a;</label>
        <input type="text" class="form-control" placeholder="请输入卡号" required autofocus style="margin:0px 0px 3px 0px;" name="CardNo"/>
        <label for="inputPassword" class="sr-only">&#x624b;&#x673a;&#x53f7;&#x540e;&#x56db;&#x4f4d;&#xff1a;</label>
        <input type="text" class="form-control" placeholder="请输入手机号后四位" required autofocus style="margin:0px 0px 3px 0px;" name="MobileNo"/>
        <input type="text" id="indentityCode" class="form-control" placeholder="请输入验证码" required style="margin:0px 0px 3px 0px;" name="imageCode" maxlength="4">
        <img class="image-indentity pull-right" style="margin:0px 8px 0px 0px;" src="kimageCodeAct.do?random=201504301102343603&ebf_cookie=evniwmih5jg3m4gz4c5uxuch" alt="" />
            
        <input type="hidden" name="MerchantID" value=""/> 
        <input type="hidden" name="MerchantName" value="******"/>   
        <input type="hidden" name="OrderNo" value="J000302015043011025128810001"/>
        <input type="hidden" name="OrderAmount" value="3.50"/>
        <input type="hidden" name="OrderDate" value="2015/4/30 0:00:00"/>
        <input type="hidden" name="OrderTime" value="2015/4/30 11:02:51"/>
        <input type="hidden" name="abc_formId" value="9999"/>
        <input type="hidden" name="isRead" value="0"/>
        <input type="hidden" name="payment" value="1"/>
        <input type="hidden" name="TokenTmp" value="14303629533850965238"/>
        <input type="hidden" name="payTypeTmp" value="1010"/>
        <br />
        <button class="btn btn-lg btn-abc btn-block" type="submit" onclick="">确定</button>
        <input type="hidden" name="ebf_cookie" value="evniwmih5jg3m4gz4c5uxuch"/></form>
        <br /><br />
      
      
      <p class="text-center sr-only">m.abchina.com</p>
      <p class="text-center sr-only">全国24小时服务热线:95599</p>
      <p class="text-center sr-only">中国农业银行版权所有</p>
    </div><!-- /.container -->


    <p class="text-center">
        m.abchina.com<br />
        &#x5168;&#x56fd;24&#x5c0f;&#x65f6;&#x670d;&#x52a1;&#x70ed;&#x7ebf;&#xff1a;95599<br />
        &#x4e2d;&#x56fd;&#x519c;&#x4e1a;&#x94f6;&#x884c;&#x7248;&#x6743;&#x6240;&#x6709;
    </p>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/jquery-2.1.3.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>



这个页面的所有元素,<img>只能取得
 <img class="image-abclogo" src="https://mobile.abchina.com/mpay/mobileBank/zh_CN/EBusinessModule/image/abclogo.png"></img>

而无法取到
<img class="image-indentity pull-right" style="margin:0px 8px 0px 0px;" src="kimageCodeAct.do?random=201504301102343603&ebf_cookie=evniwmih5jg3m4gz4c5uxuch" alt="" />


使用 doc.select("[src]"); 也无法得到此<img>
------解决思路----------------------
1.你贴的源码是 浏览器复制的,还是jsoup采集下来打印的

2,如果是复制的,那么请使用jsoup 访问并打印,看看是否存在你说的那个img

3,按照你的描述应该是不存在你说的img,这个img可能是js生成的。

4如果是js生成的,那么你就要研究一下这个页面的js,然后找到这个生成url的js自己生成一下就ok了

5,得到url之后,需要注意的是,请求这个url的时候,你要保持你这个页面的会话,也就是sessionid,有的网站可能对rf也有要求,建议是使用谷歌浏览器看一下请求的所有参数,然后全部模拟,这样获取的验证码才可能正确