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!
How to reference HTML page cached on local HDD within script
-
daws0n
- Posts: 53
- Joined: 2005-02-04 13:53:18
How to reference HTML page cached on local HDD within script
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
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.It's not 100% accurate, but does not an OK job.
-
daws0n
- Posts: 53
- Joined: 2005-02-04 13:53:18
-
antp
- Site Admin
- Posts: 9902
- Joined: 2002-05-30 10:13:07
- Location: Brussels
To read/write text files you could use something like that:
(using a classic path like 'c:\folder\file')
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;