Monday, November 21, 2011

Remove the value of the param in URL

It should be formatted your URL when doing aggregation for further analysis, here is Ruby code to be copy with the URL which includes params within it:
 string1 = "http://www.google.com.hk/search?sclient=psy-ab&hl=en&newwindow=1&safe=strict&biw=1440&bih=693&noj=1&source=hp&q=wicket+1.5+URL&oq=wicket+1.5+URL&aq=f&aqi=g2&aql=&gs_sm=e&gs_upl=3231l4087l0l4226l4l4l0l0l0l2l302l832l2-2.1l3l0";  
 if (string1.include? "?")  
  string1.insert(-1, "&")  
  string1.gsub!(/=(.*?)&/, "&")  
  puts string1.chomp!("&")  
 end  
The output result:
 http://www.google.com.hk/search?sclient&hl&newwindow&safe&biw&bih&noj&source&q&oq&aq&aqi&aql&gs_sm&gs_upl  

No comments:

Post a Comment