任务是这样的,老师给我一张 Excel 表格,列了 400 多本期刊的标题,而后给了我一个网址(最新SCI影响因子查询及期刊投稿分析系统(2015-2016年) - LetPub),让我从这网站获取这些期刊的影响因子。这网站能够根据期刊名返回期刊信息,影响因子就在其中。考虑到连接可能失效,我给出一个截图,以下。php
咱们须要用 webread 函数向网站提交咱们要检索的期刊名,而后接收网站返回的网页源代码,最后从源代码中利用正则表达式提取出影响因子。html
提交期刊名时要在 webread 函数中指定网站上相关的变量名和变量值,变量值就是咱们要检索的期刊名。那变量名怎么查看呢,其实变量名就是输入期刊名那个 input box 的 id,看图。python
url = 'http://www.letpub.com.cn/index.php?page=journalapp&view=search';
source_page = webread(url, 'searchname', char(journal_names(i)));
这样网页源码就储存到了 source_page 变量中,接下来咱们从 source_page 中提取出影响因子。相似地,咱们观察下包含影响因子的语句。web
<td style="border:1px #DDD solid; border-collapse:collapse; text-align:left; padding:8px 8px 8px 8px;">2.603</td>
咱们构造一个正则表达式,而且用 matlab 的 regexp 函数匹配。正则表达式
pattern = '>[0-9]\.[0-9][0-9][0-9]<';
IF = regexp(source_page, pattern, 'match');
通过试验,pattern 两端的 >< 符号应该保留,否则会匹配到不想要的结果。浏览器
下面给出完整的包含输入输出、循环的代码。须要注意的是,若是想运行这段代码须要读者自行构建输入文件,而且修改代码中输入文件的路径。另请注意,matlab 2015a 之前的版本没有 webread 函数,所以该教程不适用。app
%% search impact factors from website for prof. Zhou.
%% read journal names from the file provided by Zhou
statics_filename = 'H:\impact factor\statics20170224.xlsx';
[~, journal_names, ~] = xlsread(statics_filename, 'A2:A475');
%% save the pages from the website and match the impact factors.
n = size(journal_names);
statics_result = cell(n);
for i = 1:n
url = 'http://www.letpub.com.cn/index.php?page=journalapp&view=search'; % provided by Zhou
source_page = webread(url, 'searchname', char(journal_names(i)));
% match the impact factor from the source.
pattern = '>[0-9]\.[0-9][0-9][0-9]<';
IF = regexp(source_page, pattern, 'match');
IF = strjoin(IF);
statics_result(i) = {IF};
disp(i);
disp(IF);
end
%% write the statics file.
xlswrite(statics_filename, statics, 2);