Page 1 of 1

How to reference HTML page cached on local HDD within script

Posted: 2015-10-12 10:57:00
by daws0n
I have created a crude script to pull down * ratings from a website into a custom field in my catalog.

It works, but I don't really want to hammer the site with queries. Since the script points to a static address/webpage, I have saved the the single page of HTML code to my HDD.

How can I refernence that instead? Changing the "GetPage" value as below returns a 404 not found error.

page := GetPage('file:///D:/amctest/3.5%20star.htm');
page := GetPage('D:\amctest\3.5 star.htm');

Is there another function I need to use in order to query local hosted files / plain text?

Thanks!

Posted: 2015-10-12 11:08:10
by daws0n

Code: Select all

s := GetField(fieldOriginalTitle);
page := GetPage('D:\amctest\3.5 star.htm'); 
value := textbetween(page, '<h1 id="search-results">', '<hr class="no-css" />');
value := FullTrim(value);
i := Pos(s, value);
if i > 1 then
begin
setCustomField('JBStarRating', '3.5');
end;
end.
Basically, if there an "original title" match in the file the custom rating is adjusted accordingly. I have saved the webpage for each star rating.

It's not 100% accurate, but does not an OK job.

Posted: 2015-10-12 11:53:10
by daws0n
I've worked around it by enabling localhost and placing the files in C:\inetpub\wwwroot

Posted: 2015-10-13 20:30:33
by antp
To read/write text files you could use something like that:

Code: Select all

function LoadFromFile(FileName: string): string;
var
  Page: TStringList;
begin
  Page := TStringList.Create;
  Page.LoadFromFile(FileName);
  Result := Page.Text;
  Page.Free;
end;

Code: Select all

procedure SaveToFile(Text: string; FileName: string);
var
  Page: TStringList;
begin
  Page := TStringList.Create;
  Page.Text := Text;
  Page.SaveToFile(FileName);
  Page.Free;
end;
(using a classic path like 'c:\folder\file')