2014-04-27 16 views
13

मैं here enter image description here स्रोत कोड में प्रवेश करना चाहते हैंjsoup का उपयोग करके फॉर्म लॉगिन कैसे पोस्ट करें?

<HTML><HEAD><TITLE>:: Dhaka Electric Supply Company Limited (DESCO)::</TITLE> 
<META http-equiv=Content-Type content="text/html; charset=utf-8"> 
<META http-equiv=Pragma content=no-cache> 
<META http-equiv=imagetoolbar content=no> 
<META content="Home Page of Dhaka Electric Supply Company Limited" name=description> 
<META content="MSHTML 6.00.2900.2180" name=GENERATOR> 
<style type="text/css"> 
    img{ 
     border:0px; 
    } 
</style> 
<script type="text/javascript" src="js/ajax-dynamic-content.js"></script> 
<script type="text/javascript" src="js/ajax.js"></script> 
<script type="text/javascript" src="js/ajax-tooltip.js"></script> 
<link rel="stylesheet" href="css/ajax-tooltip.css" media="screen" type="text/css"> 
<link rel="stylesheet" href="css/ajax-tooltip-demo.css" media="screen" type="text/css"> 
<LINK media=all href="css/global.css" type=text/css rel=stylesheet> 


</HEAD> 
<BODY> 
<DIV id=over style="DISPLAY: none"></DIV> 
<DIV class=baselayout> 
<DIV class=pagetopshadow></DIV> 
<DIV class=basebg> 
<DIV class=pageleft></DIV> 
<DIV class=pagecenter> 
<DIV id=Header> 
</DIV> 
<DIV id=Menu> 
</DIV> 
<DIV id=HomeContent> 
<DIV class=right> 
<DIV class=homeintro> 

<div style="padding-top: 0px;"> 
<script> 
function checkLogin() 
{ if(document.login.username.value == '') 
    { 
    alert('Please enter your account number'); 
    return false; 
    }return true; 
    } 
    alert('Payments through VISA and Master Card are stopped by DBBL. only DBBL Nexus card is allowed.'); 
    </script> 

     <form NAME='login' METHOD='POST' ACTION='authentication.php'> 

      <table width="350" height="181"cellpadding='0' cellspacing='0' border='0' style="border:#e5e5e5 0px solid; BACKGROUND: url(css/images/top9.png) no-repeat left top;" align="center"> 
      <tr> <td rowspan="6" style="padding-left:15px;"><img src="css/images/groupperms.gif" width="50" height="50"><td></tr> 
      <tr> 
       <td colspan="2" height="50"></td> 
      </tr> 
      <tr> 
       <td nowrap><span class="textcolor1">Account No. </span></td> 
       <td><input type='text' name='username' style="border:#cacaca 2px solid; color:#000099;" value=''></td></tr> 

      <tr> 
      <td> <a class="uiTooltip" href="#" onMouseOver="ajax_showTooltip(window.event,'tooltip/help.html',this);return false" onMouseOut="ajax_hideTooltip()">Help</a></td> 
      <td><input name="login" type='submit' value='Login' style="width:80px; font-family:Arial, Helvetica, sans-serif; font-weight:bold; color:#FFFFFF; border:#000000 2px solid; cursor:pointer; background-color: #1b4585;" border="0" align="right" title="Login" onClick="return checkLogin();"/></td> 
      </tr> 

     </table> 

     </form> 
<table width="630" border="0" cellspacing="2" cellpadding="2" align="center" bgcolor="#FFFFFF" bordercolor="#FFFFFF"> 
    <tr> 
    <td width="80"></td> 
    <td><img src="images/right_3.gif"/></td> 
    <td><span class="textcolor"><strong><a href='https://www.desco.org.bd/index.php?page=internet-bill-payment' target="_blank" class="uiTooltip">Before, use this facility/services please read instructions...</a></strong></span></td> 
    </tr> 
    </table> 
<p align="center" class="textcolor"><strong><a href='https://www.desco.org.bd' class="uiTooltip">Back Home</a></strong></p> 
<table align="center" width="135" border="0" cellpadding="2" cellspacing="0" title="Click to Verify - This site chose VeriSign SSL for secure e-commerce and confidential communications."> 
<tr> 
<td width="135" align="center" valign="top"><script type="text/javascript" src="https://seal.verisign.com/getseal?host_name=www.desco.org.bd&amp;size=S&amp;use_flash=YES&amp;use_transparent=YES&amp;lang=en"></script><br /> 
<a href="http://www.verisign.com/ssl-certificate/" target="_blank" style="color:#000000; text-decoration:none; font:bold 7px verdana,sans-serif; letter-spacing:.5px; text-align:center; margin:0px; padding:0px;">ABOUT SSL CERTIFICATES</a></td> 
</tr> 
</table> 


</div> 
<div align="center" style="padding-top:10px;"> 



<CENTER><B> 
    Total Visits: 1</B></CENTER> 
</div> 
</DIV> 
</DIV> 
</DIV> 
</DIV> 
<DIV class=pageright></DIV></DIV> 
<DIV class=pagebotshadow> 
<DIV id=Footer>Copyright © 2010 Dhaka Electric Supply Company Ltd. All rights reserved.</DIV> 
</DIV> 
</DIV> 
</BODY> 
</HTML> 
मूल रूप से कोड के नीचे

रूप

<form NAME='login' METHOD='POST' ACTION='authentication.php'> 

     <table width="350" height="181"cellpadding='0' cellspacing='0' border='0' style="border:#e5e5e5 0px solid; BACKGROUND: url(css/images/top9.png) no-repeat left top;" align="center"> 
     <tr> <td rowspan="6" style="padding-left:15px;"><img src="css/images/groupperms.gif" width="50" height="50"><td></tr> 
     <tr> 
      <td colspan="2" height="50"></td> 
     </tr> 
     <tr> 
      <td nowrap><span class="textcolor1">Account No. </span></td> 
      <td><input type='text' name='username' style="border:#cacaca 2px solid; color:#000099;" value=''></td></tr> 

     <tr> 
     <td> <a class="uiTooltip" href="#" onMouseOver="ajax_showTooltip(window.event,'tooltip/help.html',this);return false" onMouseOut="ajax_hideTooltip()">Help</a></td> 
     <td><input name="login" type='submit' value='Login' style="width:80px; font-family:Arial, Helvetica, sans-serif; font-weight:bold; color:#FFFFFF; border:#000000 2px solid; cursor:pointer; background-color: #1b4585;" border="0" align="right" title="Login" onClick="return checkLogin();"/></td> 
     </tr> 

    </table> 

    </form> 

enter image description here

मैं इस

package jsouptest; 

import org.jsoup.Connection; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 

public class JsouptTest { 
    public static void main(String[] args) throws Exception { 

     Connection.Response loginForm = Jsoup.connect("https://www.desco.org.bd/ebill/login.php") 
       .method(Connection.Method.GET) 
       .execute(); 

     Document document = Jsoup.connect("https://www.desco.org.bd/ebill/login.php") 
       .data("cookieexists", "false") 
       .data("username", "32007702") 
       .data("login", "Login") 
       .cookies(loginForm.cookies()) 
       .post(); 
     System.out.println(document); 

    } 

} 
कोशिश कर रहा हूँ है 63,210

लेकिन im त्रुटि नीचे हो रही

Exception in thread "main" java.net.SocketTimeoutException: Read timed out 
    at java.net.SocketInputStream.socketRead0(Native Method) 
    at java.net.SocketInputStream.read(SocketInputStream.java:152) 
    at java.net.SocketInputStream.read(SocketInputStream.java:122) 
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) 
    at sun.security.ssl.InputRecord.read(InputRecord.java:480) 
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) 
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323) 
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) 
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) 
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:439) 
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424) 
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178) 
    at jsouptest.JsouptTest.main(JsouptTest.java:12) 

बजे कुछ याद आ रही है? इसे कैसे जोड़ेंगे?

उत्तर

23

POST अनुरोध करने के लिए आप जिस यूआरएल का उपयोग कर रहे हैं वह गलत है, क्योंकि जब आपको किसी फॉर्म के लिए एक विशिष्ट अनुरोध करना है तो आपको फॉर्म टैग में मौजूद वेब पेज का उपयोग करना चाहिए, इस मामले में "authentication.php"।

तो कोड होगा:

package jsouptest; 

    import org.jsoup.Connection; 
    import org.jsoup.Jsoup; 
    import org.jsoup.nodes.Document; 

    public class JsouptTest { 
     public static void main(String[] args) throws Exception { 

      Connection.Response loginForm = Jsoup.connect("https://www.desco.org.bd/ebill/login.php") 
      .method(Connection.Method.GET) 
      .execute(); 

      Document document = Jsoup.connect("https://www.desco.org.bd/ebill/authentication.php") 
      .data("cookieexists", "false") 
      .data("username", "32007702") 
      .data("login", "Login") 
      .cookies(loginForm.cookies()) 
      .post(); 
      System.out.println(document); 

     } 

    } 

यह एक सही ढंग से वेब पेज है कि आप चाहते हैं प्राप्त करता है।

0

मेरे लिए समस्या यह थी कि मैंने व्यूस्टेट, ईवेंट वैधता, viewstategenerator मान नहीं भेजे थे।

इन मानों को प्राप्त करने के लिए आपको पहले लॉगिन फॉर्म पेज पर एक GET अनुरोध भेजना होगा। मेरे उदाहरण में यह एक डिफ़ॉल्ट.aspx पृष्ठ था।

फिर आपको उन मानों को निकालना होगा और उन्हें चर में रखना होगा। इसके अलावा आपको अन्य चीज़ों के साथ फॉर्म लॉगिन और पासवर्ड फ़ील्ड आईडी, सबमिट बटन की आईडी की आवश्यकता है। भेजे गए सभी चर की एक सूची के लिए, मैन्युअल रूप से लॉगिन करें और POST अनुरोध के लिए नेटवर्क टैब को देखने के लिए क्रोम देव उपकरण (तत्वों का निरीक्षण करें) का उपयोग करें। इसके अंदर आपके द्वारा सबमिट किए गए उपयोगकर्ता नाम और पासवर्ड को दिखाना चाहिए। वहां आपको भेजे गए अन्य चर दिखाई देंगे।

network tab in dev tools example

इसके बाद, उन सभी चर सहित एक पोस्ट अनुरोध भेजने के एक चर में प्रतिक्रिया से कुकीज़ बचाने के लिए, और आप तो उपयोग कर सकते हैं कि एक पृष्ठ पर जाने के लिए।

कोड:

import java.io.IOException; 
import java.util.Map; 
import org.jsoup.Connection; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.nodes.FormElement; 


public class get_example { 

public static void main(String[] args) throws IOException { 
    //=================================== 
    Connection.Response response2 = Jsoup.connect("yourloginpage") 
      .method(Connection.Method.GET) 
      .execute(); 

    Document responseDocument = response2.parse(); 

    Element eventValidation = responseDocument.select("input[name=__EVENTVALIDATION]").first(); 
    Element viewState = responseDocument.select("input[name=__VIEWSTATE]").first(); 
    Element viewStateGen = responseDocument.select("input[name=__VIEWSTATEGENERATOR]").first(); 



    Connection.Response response = Jsoup.connect("yourloginpage") 
      .method(Connection.Method.POST) 
      .data("ctl00$plnMain$txtLogin", "username") 
      .data("ctl00$plnMain$txtPassword", "password") 
      .data("ctl00$plnMain$Submit1", "Log In") 
      .data("ctl00$ucCopyright$hdnPrivacyStatement", "Privacy Statement") 
      .data("ctl00$ucCopyright$hdnTermsOfUse", "Terms of Use") 
      .data("__VIEWSTATE", viewState.attr("value")) 
      .data("__VIEWSTATEGENERATOR", viewStateGen.attr("value")) 
      .data("__EVENTVALIDATION", eventValidation.attr("value")) 
      .execute(); 


    Map<String, String> cookies = response.cookies(); 


    Document homePage = Jsoup.connect("anotherpage") 
      .cookies(cookies) 
      .get(); 


    System.out.println(homePage.body().html()); 

} 
} 
0

मेरे मामले में, यह तीन चरणों में होते हैं:

  1. जाओ लॉगिन प्रपत्र पेज से कुकीज़;
  2. फॉर्म action= यूआरएल लॉगिन करने के लिए पोस्ट प्रमाण पत्र, कुकीज़ नवीनीकृत;
  3. उपयोगकर्ता को इंडेक्स पेज पर रीडायरेक्ट किया जाएगा। यहां पार्स न करें, अंतिम लक्ष्य URL पर केवल Response भेजें।
  4. पार्स जब आप अंतिम पृष्ठ तक पहुंचते हैं।

कुकीज़ को प्रत्येक चरण में नवीनीकृत किया जाना चाहिए, कभी-कभी प्रविष्टियां जोड़ना चाहिए, और कभी-कभी आपको इसे साफ़ करना और रीसेट करना होगा। नेटवर्क पैनल में cookies भाग में इंटरनेट एक्सप्लोरर/क्रोम/फ़ायरफ़ॉक्स देव उपकरण (एफ 12) के साथ नेटवर्क ट्रांसमिशन की जांच करना सुनिश्चित करें।

संबंधित मुद्दे