简体   繁体   中英

Get individual values from Third Party Response Data in HTML page

I need a help for How to get Individual values from HTML page. i got response from some PAYU payment gateway team in HTML page but i need individual attributes values from tacking Transaction

Below is the response am getting from PAYU Team:

<h1>This is the success url</h1>
<p>Your transaction is completed successfully. Bank response is 
   mihpayid=403993715514374636&amp;mode=&amp;status=failure&amp;unmappedstatus=userCancelled&amp;key=gtKFFx&amp;txnid=txn1r23fw&amp;amount=100.00&amp;discount=0.00&amp;net_amount_debit=0.00&amp;addedon=2016-04-25+10%3A48%3A29&amp;productinfo=oxygenconcentrator&amp;firstname=test&amp;lastname=&amp;address1=&amp;address2=&amp;city=&amp;state=&amp;country=&amp;zipcode=&amp;email=test%40gmail.com&amp;phone=8152709721&amp;udf1=&amp;udf2=&amp;udf3=&amp;udf4=&amp;udf5=&amp;udf6=&amp;udf7=&amp;udf8=&amp;udf9=&amp;udf10=&amp;hash=6a9d21bd423d61cd5a7d91098aa1140314e45eaddd8d4b9148399caba8ac61a9476aec130eb369f7d526e741b1b6c47b1ca71bec21fa69aa3deaa13740dbffbc&amp;field1=&amp;field2=&amp;field3=&amp;field4=&amp;field5=&amp;field6=&amp;field7=&amp;field8=&amp;field9=Cancelled+by+user&amp;payment_source=payu&amp;PG_TYPE=&amp;bank_ref_num=&amp;bankcode=&amp;error=&amp;error_Message=
</p>

 <script>
PayU.onSuccess("mihpayid=403993715514374636&amp;mode=&amp;status=failure&amp;unmappedstatus=userCancelled&amp;key=gtKFFx&amp;txnid=txn1r23fw&amp;amount=100.00&amp;discount=0.00&amp;net_amount_debit=0.00&amp;addedon=2016-04-25+10%3A48%3A29&amp;productinfo=oxygenconcentrator&amp;firstname=test&amp;lastname=&amp;address1=&amp;address2=&amp;city=&amp;state=&amp;country=&amp;zipcode=&amp;email=test%40gmail.com&amp;phone=8152709721&amp;udf1=&amp;udf2=&amp;udf3=&amp;udf4=&amp;udf5=&amp;udf6=&amp;udf7=&amp;udf8=&amp;udf9=&amp;udf10=&amp;hash=6a9d21bd423d61cd5a7d91098aa1140314e45eaddd8d4b9148399caba8ac61a9476aec130eb369f7d526e741b1b6c47b1ca71bec21fa69aa3deaa13740dbffbc&amp;field1=&amp;field2=&amp;field3=&amp;field4=&amp;field5=&amp;field6=&amp;field7=&amp;field8=&amp;field9=Cancelled+by+user&amp;payment_source=payu&amp;PG_TYPE=&amp;bank_ref_num=&amp;bankcode=&amp;error=&amp;error_Message=");
 </script>

I got this response from below snippet

iabRef.executeScript(
   { code: "document.body.innerHTML" },
    function( values ) {
        alert(values[0]);
        console.log(values[0]);
    }
  );

so i need individual attribute values like mihpayid , mode , status and so on......

Assuming that values or values[0] will have : "mihpayid=403993715514374636&mode=&status=failure&unmappedstat"

Then you could write a function as below:

   function extractScript(source){
     var pattern = /<script>(\w+)<\/script>/
     var matches = source.match(pattern);

     return matches[1];
   }

function getValue(source, key){
      var pattern = key+'=(\\w+)(&amp;)?';
      var expr = new RegExp(pattern);

      var result = source.match(expr);

      return result[1];
 }

Then in executeScript:

iabRef.executeScript(
{ code: "document.body.innerHTML" },
  function( values ) {
   //incase values[0] contains result string
   console.log(getValue(values[0], 'mihpayid'))
   //or
   //incase values[0] contains result string
   console.log(getValue(values, 'mihpayid'))
}
);

You can just get the contents of the p tag then perform a split twice

Assuming that p is the only p tag in the page you can get the value by calling

 var text= document.getElementByTagName('p').innerHtml;

First split the &amp;

var theArray= text.split('&amp;');//or just & depending on how your text comes out 

this will return an array that'll contain something like [status=failure,phone=8152709721] Then you can loop through this array and create an object

var obj = {} ;
//loop here then do this within the loop 
var kv=theArray[i].split('=');
obj[kv[0]] = kv[1];

So you can get your attributes by calling obj.status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM