Delphi Net.HttpClient正则批量获取网页代码中的数值


本文整理自网络,侵删。

 
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  System.Classes,
  System.Net.HttpClient,
  System.RegularExpressions;

const
  url = 'http://www.delphitop.com/';
var
matchs: TMatchCollection;
m: TMatch;
begin
  var http := THttpClient.Create;
  var sl := TStringList.Create;

  try
    sl.LoadFromStream(http.Get(url).ContentStream, TEncoding.ANSI);

matchs := TRegEx.Matches(sl.Text, '<span>(?<price>(\d+[,.])*\d+)</span>');
for m in matchs do
begin
writeln('获取信息: ', m.Groups.Item['price'].Value);
end;

      Readln;
  finally
    sl.Free;
    http.Free;
  end;
end.

相关阅读 >>

Delphi 实现 托动pagecontrol上的标签页

Delphi tgauge类的定义在哪个单元中定义的?

推荐一套免费跨平台的Delphi 哈希及加密算法库

Delphi webbrowser 跨域访问

Delphi 主窗体最小化时不显示在任务栏

Delphi hexstrtostream

Delphi 18位身份证号码的校验

Delphi executewait运行一个程序等待其结束

Delphi 字符串与日期格式互转

Delphi Delphi tparallel cleanup needed用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...