matlab抓取网页数据
clc;
clear;
warning off;
% = urlread(sprintf('http://trend.baidu.lecai.com/fc3d/baseTrend.action?recentPhase=30&onlyBody=false&phaseOrder=up&coldHotOrder=number'));
%这个是彩票数据的网址
=urlread(sprintf('http://888.qq.com/static/chart/fc3d/'));
if ~status
error('读取错误\n')
end
%获取日期
expr1='<td align="center">(\d\d\d\d-\d\d-\d\d)</td>';
= regexp(sourcefile, expr1, 'match', 'tokens');
date = cell(size(date_tokens));
for idx = 1:length(date_tokens)
date{idx} = date_tokens{idx}{1}; %length(date_tokens)行1列
end
%%获取3D的三位数字
expr2='<td class="chartBall01" width=18>(\d)</td>';
= regexp(sourcefile, expr2, 'match', 'tokens');
data = zeros(size(data_tokens));
for idx = 1:length(data_tokens)
data(idx) = str2double(data_tokens{idx}{1});
end
data1=reshape(data,3,length(data)/3)';
%%%数据存储外部文件
fprintf('完成!\n')
转自:http://blog.163.com/zzz216@yeah/blog/static/162554684201412091844681/
页:
[1]