2013-04-11 70 views
0

我收到一个字符串响应,使用rest-client gem和semrush api。如何访问字符串中的特定数据?访问REST响应数据

响应:

keyword;Position;Previous Position;Search Volume;CPC;Url;Traffic (%);Traffic Cost (%);Competition;Number of Results;Trends 
seo;11;0;90500;10.88;http://www.seobook.com/;6.55;11.32;0.91;839000000;0.00,0.00,0.82,0.82,0.82,0.99,0.99,0.99,0.99,0.99,0.99,0.99 
seo tools;1;1;8100;8.89;http://tools.seobook.com/;5.86;8.28;0.94;71100000;0.00,0.00,0.24,0.24,0.30,0.45,0.45,0.36,0.36,0.55,0.99,0.36 
seo;12;8;90500;10.88;http://tools.seobook.com/;1.81;3.13;0.91;839000000;0.00,0.00,0.82,0.82,0.82,0.99,0.99,0.99,0.99,0.99,0.99,0.99 
seo training;1;1;2400;12.83;http://training.seobook.com/;1.73;3.54;0.93;27100000;0.00,0.00,0.66,0.45,0.55,0.99,0.83,0.83,0.66,0.83,0.83,0.83 
seo link building;1;1;2400;12.71;http://www.seobook.com/archives/001792.shtml;1.73;3.50;0.85;30500000;0.00,0.00,0.30,0.11,0.13,0.99,0.43,0.55,0.36,0.55,0.55,0.55 
seo tool;1;1;1600;7.96;http://tools.seobook.com/;1.15;1.46;0.82;28000000;0.00,0.00,0.34,0.20,0.30,0.83,0.55,0.55,0.45,0.83,0.83,0.99 
seo book;1;1;1600;9.61;http://www.seobook.com/;1.15;1.76;0.30;38300000;0.00,0.00,0.30,0.25,0.34,0.55,0.66,0.83,0.55,0.66,0.99,0.55 
free seo tools;1;1;1600;4.59;http://tools.seobook.com/;1.15;0.84;0.90;31500000;0.00,0.00,0.68,0.53,0.53,0.84,0.84,0.99,0.84,0.84,0.84,0.84 
seobook;1;1;1000;10.36;http://www.seobook.com/;0.72;1.19;0.02;985000;0.00,0.00,0.55,0.68,0.68,0.68,0.77,0.77,0.77,0.99,0.99,0.99 
seo rank checker;1;1;880;4.96;http://tools.seobook.com/firefox/rank-checker/;0.63;0.50;0.73;5470000;0.00,0.00,0.46,0.25,0.31,0.46,0.46,0.99,0.31,0.38,0.31,0.38 

回答

0

可以存储在一个字符串的响应(我会简单地把它response),然后换行的字符串。

现在,您可以用分号分隔每行并将这些值存储在数组中。

因此,我们假设我想从seo rank checker行中获得值880

line = response.each_line.to_a.last 
array = line.split(";") 
value = array[3]