首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Delphi正则表达式IMDB

Delphi正则表达式IMDB
EN

Stack Overflow用户
提问于 2014-08-25 08:39:44
回答 1查看 224关注 0票数 0

我正在尝试将这个c#类移植到Delphi:csharp.htm

我已经准备好了帮助类,如MAtchAll等,并编写了从WebPage获取http的代码。

但我的问题是这句话:

代码语言:javascript
运行
复制
ArrayList imdbUrls = matchAll(@"<a href=""(http://www.imdb.com/title/tt\d{7}/)"".*?>.*?</a>", html);

这是我的MatchAll版本

代码语言:javascript
运行
复制
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版本

代码语言:javascript
运行
复制
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?

延斯·博里肖特

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-25 09:15:37

这做了勾选:www\.imdb\.com/title/tt\d{7}

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25482036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档