مشكور أخى على المساعدة والأكود المفيدة , ولكن انا قمت بكتابة كود البحث داخل memo لكى يستخرج الرابط فلبرنامج يقوم بتحويل موقع الأنسغرام إلى صفحة html داخل memo 1 ويقوم بفلترة و يستخراج رابط الصورة فى momo2 , الكود يعمل جيدا ولكن انا أريد فقط ان يتوقف عند كلمة .jpg , بدون إظهار باقى أكواد صفحة html , الموجودة داخل memo 2 وهذا هو الكود كامل حتى تتضح الصورة الموجودة فى السؤال الأول
مشكور أخى على المساعدة والأكود المفيدة , ولكن انا قمت بكتابة كود البحث داخل memo لكى يستخرج الرابط فلبرنامج يقوم بتحويل موقع الأنسغرام إلى صفحة html داخل memo 1 ويقوم بفلترة و يستخراج رابط الصورة فى momo2 , الكود يعمل جيدا ولكن انا أريد فقط ان يتوقف عند كلمة .jpg , بدون إظهار باقى أكواد صفحة html , الموجودة داخل memo 2 وهذا هو الكود كامل حتى تتضح الصورة الموجودة فى السؤال الأول
كود :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, MSHTML, ActiveX;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
source: TMemo;
dest: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Extracteur(Source,c1,c2:string):string;
begin
Source := Copy(Source, Pos(c1, Source)+length(c1), length(Source));
result:=Source;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
Document: IHtmlDocument2;
begin
edit1.text:=url;
document := webbrowser1.document as IHtmlDocument2;
source.lines.add(trim(document.body.innerHTML));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('https://www.instagram.com/cristiano/');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
dest.Text:= Extracteur(source.Text, 'img class="_iv4d5" src="','"');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
WebBrowser1.Navigate(dest.Lines.GetText);
end;(13-04-2017, 12:55 AM)Delphi4Us كتب : هذا الكود سيعرض لك ما تحدده فقط صورة لينك او اي شئ من الصفحة
كود :Title: How to get the Selected Objects in a TWebbrowser procedure TForm1.Button1Click(Sender: TObject); begin if Webbrowser1.OleObject.Document.Selection.type = 'Control' then begin if Webbrowser1.OleObject.Document.Selection.CreateRange.CommonParentElement.tagName = 'IMAGE' then ShowMessage('An Image is selected'); end else begin if Webbrowser1.OleObject.Document.Selection.createRange.Text = '' then ShowMessage('Nothing is selected - '); end; end;
هذا سوف يعطيك كل الروابط التي بالصفحة
كود :Title: How to list all links of a page of a TWebbrowser procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin for i := 0 to Webbrowser1.OleObject.Document.links.Length - 1 do Listbox1.Items.Add(Webbrowser1.OleObject.Document.Links.Item(i)); end; {*****************} { if there are frames } procedure TForm1.Button2Click(Sender: TObject); var u : variant; v : IDispatch; s : string; procedure RecurseLinks(htmlDoc: variant); var BodyElement : variant; ElementCo: variant; HTMLFrames: variant; HTMLWnd : variant; j, i : integer; begin if VarIsEmpty(htmlDoc) then exit; BodyElement := htmlDoc.body; if BodyElement.tagName = 'BODY' then begin ElementCo := htmlDoc.links; j := ElementCo.Length - 1; for i := 0 to j do begin u := ElementCo.item(i); s := u.href; listLinks.Items.Add(s); end; end; HTMLFrames := htmlDoc.Frames; j := HTMLFrames.length - 1; for i := 0 to j do begin HTMLWnd := HTMLFrames.Item(i); RecurseLinks(HTMLWnd.Document); end; end; // RecurseLinks begin v := WebBrowser1.document; listLinks.Clear; RecurseLinks(v); end;
هذا سيعطيك النص الذي تضلله
كود :Title: How to find and highlight text in TWebBrowser private procedure SearchAndHighlightText(aText: string); {....} uses mshtml; { .... } procedure TForm1.SearchAndHighlightText(aText: string); var tr: IHTMLTxtRange; //TextRange Object begin if not WebBrowser1.Busy then begin tr := ((WebBrowser1.Document as IHTMLDocument2).body as IHTMLBodyElement).createTextRange; //Get a body with IHTMLDocument2 Interface and then a TextRang obj. with IHTMLBodyElement Intf. while tr.findText(aText, 1, 0) do //while we have result begin tr.pasteHTML('' + tr.htmlText + ''); //Set the highlight, now background color will be Lime tr.scrollIntoView(True); //When IE find a match, we ask to scroll the window... you dont need this... end; end; end; Usage Example: procedure TForm1.Button1Click(Sender: TObject); begin SearchAndHighlightText('delphi'); end;
جرب هذا يعطيك ايضا الروابط
كود :Title: get all Frame URLs in TWebbrowser? procedure TForm1.Button2Click(Sender: TObject); var i: Integer; begin Listbox1.Clear; //if frames available if Webbrowser1.OleObject.Document.Frames.Length 0 then begin //walk through all frames and get the url //to the Listbox for i := 0 to Webbrowser1.OleObject.Document.Frames.Length - 1 do begin Listbox1.Items.Add(Webbrowser1.OleObject.Document.Frames.item(i).Document.URL); end; end; end;
مشكور أخى على المساعدة والأكود المفيدة , ولكن انا قمت بكتابة كود البحث داخل memo لكى يستخرج الرابط فلبرنامج يقوم بتحويل موقع الأنسغرام إلى صفحة html داخل memo 1 ويقوم بفلترة و يستخراج رابط الصورة فى momo2 , الكود يعمل جيدا ولكن انا أريد فقط ان يتوقف عند كلمة .jpg , بدون إظهار باقى أكواد صفحة html , الموجودة داخل memo 2 وهذا هو الكود كامل حتى تتضح الصورة الموجودة فى السؤال الأول
كود :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, MSHTML, ActiveX;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
source: TMemo;
dest: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Extracteur(Source,c1,c2:string):string;
begin
Source := Copy(Source, Pos(c1, Source)+length(c1), length(Source));
result:=Source;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
Document: IHtmlDocument2;
begin
edit1.text:=url;
document := webbrowser1.document as IHtmlDocument2;
source.lines.add(trim(document.body.innerHTML));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('https://www.instagram.com/cristiano/');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
dest.Text:= Extracteur(source.Text, 'img class="_iv4d5" src="','"');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
WebBrowser1.Navigate(dest.Lines.GetText);
end;
