regex - Finding a value in HTTP response content using Perl Script -


i have perl script http request. repsonse content like

$var1 = \'{"resultset": {   "result": [     {       "rank": "999999",       "term": "shampoo"     },     {       "rank": "999999",       "term": "beauty",       "url": "/search/results.jsp?ntt=shampoo&n=359434"     },     {       "rank": "999999",       "term": "baby, kids & toys",       "url": "/search/results.jsp?ntt=shampoo&n=359449"     }, 

i need url property above response how can it. itried using regex my $content =~ m/:"url": "(...)"/; not getting url value. please guide.

that json. use json module parse it:

use json;  $json = decode_json ( $response -> content );  foreach $element ( @{ $json -> {resultset} -> {results} } ) {     print $element -> {url},"\n";  } 

fuller; runnable example:

#!/usr/bin/perl  use strict; use warnings; use json; use data::dumper;  $json_str = '{   "resultset": {   "result": [     {       "rank": "999999",       "term": "shampoo"     },     {       "rank": "999999",       "term": "beauty",       "url": "/search/results.jsp?ntt=shampoo&n=359434"     },     {       "rank": "999999",       "term": "baby, kids & toys",       "url": "/search/results.jsp?ntt=shampoo&n=359449"     }   ] }}';  $json = decode_json($json_str); print dumper $json; foreach $element ( @{ $json->{resultset}->{result} } ) {     print $element ->{url}, "\n" if $element->{url}; } 

in above, $json_str fills niche of content. i've made assumption have plain text, , output above result of print dumper \$content.

this prints:

$var1 = {           'resultset' => {                            'result' => [                                          {                                            'rank' => '999999',                                            'term' => 'shampoo'                                          },                                          {                                            'rank' => '999999',                                            'term' => 'beauty',                                            'url' => '/search/results.jsp?ntt=shampoo&n=359434'                                          },                                          {                                            'url' => '/search/results.jsp?ntt=shampoo&n=359449',                                            'term' => 'baby, kids & toys',                                            'rank' => '999999'                                          }                                        ]                          }         };  /search/results.jsp?ntt=shampoo&n=359434 /search/results.jsp?ntt=shampoo&n=359449 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -