Добрый вечер. Есть вопрос. Имеются 3 функции которые парсят сайт эти функции используют ListView для хранения пропарсеных результатов. Так вот мне хочетса создать чтото вроде плагин модулей тоесть 1 длл для одного сайта дальше другая длл для другого сайта. Вопрос заключаетса в том, можно ли вогнать эти функции воткнуть в длл и потом их оттуда вызывать. | Код | function ParseTags(ColumnMatch: TMatch; ListItem: TListItem): Boolean; const TypeExpression = 'alt="(.*?)"'; TitleExpression = '<a.*?>(.*?)</a>'; UrlExpression = '<a href="details\.php\?id=(\d*?)"'; var CellMatch: TMatch; begin Result := False;
// Get type. CellMatch := TRegEx.Match(ColumnMatch.Value, TypeExpression); if CellMatch.Groups.Count <> 2 then Exit; ListItem.Caption := CellMatch.Groups[1].Value; ColumnMatch := ColumnMatch.NextMatch;
// Get title. CellMatch := TRegEx.Match(ColumnMatch.Value, TitleExpression); if CellMatch.Groups.Count <> 2 then Exit; ListItem.SubItems.Add(CellMatch.Groups[1].Value); //ColumnMatch := ColumnMatch.NextMatch;
// Get ID. CellMatch := TRegEx.Match(ColumnMatch.Value, UrlExpression); if CellMatch.Groups.Count <>2 then Exit; ListItem.SubItems.Add(CellMatch.Groups[1].Value); ColumnMatch := ColumnMatch.NextMatch;
Result := True; end;
function ParseColumns(ColumnMatch: TMatch; ListView: TsListView): Boolean; const TypeExpression = 'alt="(.*?)"'; TitleExpression = '<a.*?>(.*?)</a>'; TagExpression = '<[^<]+?>'; GrabColumns = [2,3, 4, 5, 6, 7]; var ListItem: TListItem; ColumnIndex: Integer; Column: String; begin Result := False; ListItem := ListView.Items.Add; if not ParseTags(ColumnMatch, ListItem) then Exit;
// Get other columns. ColumnIndex := 0; while ColumnMatch.Success do begin if ColumnIndex in GrabColumns then begin Column := TRegEx.Replace(ColumnMatch.Value, TagExpression, ''); ListItem.SubItems.Add(Column); end; Inc(ColumnIndex); ColumnMatch := ColumnMatch.NextMatch; end;
Result := True; end;
function ParseHtml(const Input: String; ListView: TsListView): Boolean; const TableExpression = '<table.*?class="tableTorrents">(.*?)</table>'; RowExpression = '<tr.*?>(.*?)</tr>'; ColumnExpression = '<td.*?>(.*?)</td>'; var TableMatch, RowMatch, ColumnMatch: TMatch; Table, Row: String; begin Result := False; TableMatch := TRegEx.Match(Input, TableExpression, [roSingleLine]); if not TableMatch.Success then Exit; Table := TableMatch.Groups[1].Value; RowMatch := TRegEx.Match(Table, RowExpression, [roSingleLine]);
// Skip header. RowMatch := RowMatch.NextMatch; while RowMatch.Success do begin Row := RowMatch.Groups[1].Value; ColumnMatch := TRegEx.Match(Row, ColumnExpression, [roSingleLine]); if not ParseColumns(ColumnMatch, ListView) then Exit; RowMatch := RowMatch.NextMatch; end;
Result := True; end;
|
Заранее Благодарен.
|