我正在尝试将这个c#类移植到Delphi:
http://lab.abhinayrathore.com/imdb/imdb_asp_csharp.htm
我已经准备好连接Helper类,例如MAtchAll等,并编写了代码以从WebPage获取http。
但我的问题是这句话:
ArrayList imdbUrls = matchAll(@"<a href=""(http://www.imdb.com/title/tt\d{7}/)"".*?>.*?</a>", html);
这是我的MatchAll版本
function MatchAll(const aExpression, aHtml: string; i: Integer = 0): TStringDynArray;
var
ResultArray: TStringDynArray;
Match: TMatch;
begin
SetLength(ResultArray, 0);
for Match in TRegEx.Matches(aHtml, aExpression, [roMultiLine]) do
begin
SetLength(ResultArray, length(ResultArray) + 1);
ResultArray[length(ResultArray) - 1] := Match.Groups[i].Value.Trim;
end;
Result := ResultArray;
end;
我的GetUrlData版本
function RandomNext(const AFrom, ATo: Integer): string;
begin
Result := IntToStr(Random(ATo - AFrom) + AFrom);
end;
function GetUrlData(const Url: string): string;
var
Client: TIdHTTP;
begin
Client := TIdHTTP.Create(nil);
// Random IP Address
Client.Request.CustomHeaders.AddValue('X-Forwarded-For', Format('%d.%d.%d.%d', [Random(255), Random(255), Random(255), Random(255)]));
// Random User-Agent
Client.Request.CustomHeaders.AddValue('User-Agent', 'Mozilla/' + RandomNext(3, 5) + '.0 (Windows NT ' + RandomNext(3, 5) + '.' + RandomNext(0, 2) + '; rv:2.0.1) Gecko/20100101 Firefox/' +
RandomNext(3, 5) + '.' + RandomNext(0, 5) + '.' + RandomNext(0, 5));
Result := Client.Get(Url);
FreeAndNil(Client);
end;
给定此URL:
http://www.google.com/search?q=imdb+13%20sins
如何提取IMDB url?
延斯·博里绍特