我试图将从网址获取的价格值转换为数字。返回的字符串给出了带有美元符号的价格。
function [ price ] = price( url )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
x = urlread(url)
y = regexpi(x, '<span id="ajaxPrice" class="pReg" itemprop="price">(.*?)</span>','tokens')
price = y{1}{1}
end
这是我用来获取价格价值的功能。
当我使用该功能时:
material = price('url')
将输出
material = '$578.56'
我确信有一个简单的解决方案,但我很难到达那里。 num2str
返回一个空数组。先感谢您。
答案 0 :(得分:0)
function [ price ] = price( url )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
x = urlread(url)
y = regexpi(x, '<span id="ajaxPrice" class="pReg" itemprop="price">(.*?)</span>','tokens')
price = y{1}{1}
end
答案 1 :(得分:0)
未来的谷歌
function [ price ] = price( url )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
x = urlread(url)
y = regexpi(x, '<span id="ajaxPrice" class="pReg" itemprop="price">(.*?\d*)</span>','tokens')
z = y{1}{1}
a = strrep(z,'$','')
price = str2num(a)
end