可能有更好的方法來做到這一點,但由於我是一名工程學學生(而且Matlab目前是我最擅長的編程語言),所以我決定看看我是否可以通過那裏做到這一點。它的工作。當然,有些事情可能已經做得更好了(我並不真正瞭解正則表達式,所以我用了很多「findstr」)。
clear;
clc;
fid=fopen('journals.txt','w');
fprintf(fid,'');
fclose('all');
fid=fopen('journals.txt','a');
id=input('Enter the starting id number: ','s');
loop=1;
while loop==1
clc;
url=strcat('http://www.trailjournals.com/entry.cfm?id=',id)
strContents=urlread(url);
f=findstr('</TABLE>',strContents);
f=f(1)+13;
l=findstr('<p>',strContents);
l=l(end)-5;
if f>l(end)
f=findstr('<blockquote>',strContents);
f=f(1)+14;
end
p=strContents(1,f:l)
if isempty(p)==1
cprintf('red','EMPTY ENTRY!\n');
return;
end
% disp(p);
% disp('------------');
% ques=input('Does this look good? (y/n): ','s');
% disp('------------');
%
% while ques=='n'
% firstword=input('Enter the first word: ','s');
% lastword=input('Enter the last word: ','s');
% f=findstr(firstword,strContents);
% l=findstr(lastword,strContents);
% p=strContents(1,f:l+length(lastword));
% disp(p);
% disp('------------');
% ques=input('Does this look good? (y/n): ','s');
% disp('------------');
% end
fprintf(fid,p);
fprintf(fid,'\n');
fprintf(fid,'\r\n\r\n-------------------------------------------\r\n\r\n');
%Next URL: next:next+6
next=findstr('">Next</a>',strContents);
if isempty(next)==1
break;
end
next=next(1);
next=next-6;
id=strContents(1,next:next+5);
url=strcat('http://www.trailjournals.com/entry.cfm?id=',id);
end
fclose('all');
cprintf('Green','The process has been completed\n');
的
可能重複的[選項HTML刮?](http://stackoverflow.com/questions/2861/options-for-html-scraping) –
我看到如何在這種情況下是有用的,但是這不是重複的,更像是...擴展名。從HTML中提取文本是必要的,但是如何獲得腳本來「單擊下一個按鈕」? – derekantrican
你不會。逐頁複製,然後在本地處理。想要一個例子嗎?你可以自己找一些,看看這樣的userscripts:http://userscripts.org/scripts/review/396661 –