How to reference HTML page cached on local HDD within script

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
daws0n
Posts: 53
Joined: 2005-02-04 13:53:18

How to reference HTML page cached on local HDD within script

Post 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!
Last edited by daws0n on 2015-10-12 11:29:35, edited 1 time in total.
daws0n
Posts: 53
Joined: 2005-02-04 13:53:18

Post 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.
daws0n
Posts: 53
Joined: 2005-02-04 13:53:18

Post by daws0n »

I've worked around it by enabling localhost and placing the files in C:\inetpub\wwwroot
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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')
Post Reply