30-10-2025, Saat: 12:05
Ürün kodundan sonra TD tagleri arasındaki ürün özellikleri istediğinizi gözden kaçırmışım.
Örnek Çıktı
Kodlar:
Örnek Çıktı
Kodlar:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.RegularExpressions, System.JSON;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CleanHTMLTags(const S: string): string;
begin
// Tüm HTML taglerini kaldır
Result := TRegEx.Replace(S, '<[^>]+>', '', [roIgnoreCase]);
// Fazla boşluk, satır sonlarını temizle
Result := TRegEx.Replace(Result, '\s+', ' ', [roIgnoreCase]).Trim;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TRMatches, TDMatches: TMatchCollection;
M, TDMatch: TMatch;
RowArray, TDArray: TJSONArray;
RowObj: TJSONObject;
CleanValue: string;
HTML:string;
begin
HTML := memo1.Text; // Html memo1 içerisinde
TRMatches := TRegEx.Matches(HTML,
'<TR[^>]*?>(.*?)<\/TR>', [roIgnoreCase, roSingleLine]);
RowArray := TJSONArray.Create;
for M in TRMatches do
begin
var CodeMatch := TRegEx.Match(M.Value,
'href="\/bipolar-transistors\/([^">]+)"',
[roIgnoreCase]);
if not CodeMatch.Success then
Continue;
RowObj := TJSONObject.Create;
RowObj.AddPair('urun_kodu', CodeMatch.Groups[1].Value);
TDMatches := TRegEx.Matches(M.Value,
'<TD[^>]*?>(.*?)<\/TD>', [roIgnoreCase, roSingleLine]);
TDArray := TJSONArray.Create;
for TDMatch in TDMatches do
begin
CleanValue := CleanHTMLTags(TDMatch.Groups[1].Value);
if CleanValue <> '' then
TDArray.Add(CleanValue);
end;
RowObj.AddPair('veriler', TDArray);
RowArray.Add(RowObj);
end;
// Sonucu JSON olarak memo2 ye aktar
memo2.Lines.Clear;
memo2.Lines.Add(RowArray.Format(2));
end;
end.

