program NewbieScript; { Basic script to search Amazon for a list of books defined in c:\list.txt and output the search result per file as follows c:\amazon1.xls c:\amazon2.xls c:\amazon3.xls c:\amazon4.xls ... Please create c:\list.txt before running this script } const ExcelFile = 'c:\amazon'; sExt = '.xls'; MyList = 'c:\list.txt'; MainURL = 'http://www.amazon.com/exec/obidos/tg/browse/-/283155/sr=53-1/qid=1157654455/ref=tr_35281/103-9871813-3235806'; var sData : string; sSearchStr : string; sFilename : string; nCount : integer; { Process events here } procedure OnDocumentComplete(URL : string); begin if IsPartOf('http://www.amazon.com/exec/obidos/tg/browse/', URL) then begin // assign search string to title field Fill('field-keywords', sSearchStr); // search button does not have a name, no way to reference it, just press enter SendKeyPress('Enter'); end; if IsPartOf('http://www.amazon.com/s/ref=nb_ss_b/', URL) then begin // get all results at html table 18,1,2; use ClickCapture to get position sData := GetTableCell(23,0,2); // get next Excel filename sFilename := ExcelFile+IntToStr(nCount)+sExt; // delete this file if it exists DeleteFile(sFilename); // append extracted results to excel file TextAppendToFile(sFilename, sData); nCount := nCount + 1; if not(EndOfFile) then begin Readfl(sSearchStr); GotoURL(MainURL); end else begin CloseFile; NewbieScriptEnd; ShowMessage('Script has completed.'); end; end; end; { This is the main program body. } begin nCount := 1; Reset(MyList); if not(EndOfFile) then begin Readfl(sSearchStr); Navigate(MainURL); end; end.