stata
2013-10-04 04:31:09
Hey guys, just wondering why my code won't write to a text file. The text file is just empty, despite that the strings I'm writing to it are definitely not empty. Help would really be appreciated
P.S. code won't run since I'm not including the site url I'm scraping and filepath
P.S. code won't run since I'm not including the site url I'm scraping and filepath
program SiteScraper;
{$i SRL/SRL.simba}
{$loadlib Appa_Simba}
var
myUrl,currentStr,startStr,endStr: String;
user, i, bI, startIndex, endIndex, numEle,fileHandle: Integer;
e: TAppaElementArray;
const
URLNAME = 'url';
FILEPREF = 'C:\Users\myname\Desktop\filename';
WAITTIME = 500;
GOLDOFF = 12;
ERRORINDEX = 66;
DEL = ';';
begin
InputQuery('scraper', 'Start ID:' ,startStr);
startIndex := StrToInt(startStr);
InputQuery('scraper', 'End ID:' ,endStr);
endIndex := StrToInt(endStr);
fileHandle := CreateFile(FILEPREF+startStr+'to'+endStr+'.txt');
if fileHandle = -1 then exit;
appa_ShowForm;
wait(1000);
for user := startIndex to endIndex do
begin
myUrl := URLNAME + IntToStr(user);
appa_Navigate(myUrl);
wait(WAITTIME);
try
appa_GetElements(e);
numEle := length(e);
if (numEle > ERRORINDEX-1) and (e[ERRORINDEX].innerText = 'Error') then
begin
writeln('no user');
continue;
end;
for i := length(e) - 1 downto 0 do
begin
{writeln(e[i].innerText + '----' + IntToStr(i));}
if (e[i].innerText <> 'Group:') then continue;
bI := i;
break;
end;
// writeln(IntToStr(i));
currentStr := (IntToStr(user)+DEL+
e[bI+GOLDOFF].innerText+DEL+#13#10);
WriteFileString(fileHandle,currentStr);
writeln(currentStr);
except
WriteFileString(fileHandle,IntToStr(user)+DEL+'fail'+#13#10);
writeln('Failed navigating to: ' + myURL);
{
finally
writeln('Success');
}
end;
end;
writeln('Done');
end.