procedure TForm1.Button1Click(Sender: TObject); var ShellWindow: IShellWindows; nCount: integer; spDisp: IDispatch; i: integer; vi: OleVariant; IE1: IWebBrowser2; IDoc1: IHTMLDocument2; begin ShellWindow := CoShellWindows.Create; nCount := ShellWindow.Count; for i := 0 to nCount - 1 do begin vi := i; spDisp := ShellWindow.Item(vi); spDisp.QueryInterface( iWebBrowser2, IE1 ); if IE1 <> nil then begin memo1.Lines.Add( 'Location: '+ie1.LocationName ); IE1.Document.QueryInterface(IHTMLDocument2,iDoc1); if iDoc1 <> nil then begin memo1.Lines.add( 'Title: ' + IDOC1.Title ); memo1.Lines.add( 'Url: ' + IDOC1.url); end; end; end; end;
刚才那个不是,试试这个: unit ligwin1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } control,KeyId:integer; hotkeyid:ATOM; public { Public declarations } procedure WMHOTKEY(var Msg:TMessage);message WM_HOTKEY; end;var Form1: TForm1; ThisUrl:PChar;implementation{$R *.DFM} function EnumChildWindowsProc(H:HWnd;lparam:longint):Boolean;stdcall; var Buffer: array[0..10] of Char; begin Result:=True; GetClassName(h,buffer,10); if trim(StrPas(Buffer))='Edit' then begin SendMessage(h,WM_GETTEXT,249,Integer(ThisUrl)); Result:=False; end; end;procedure TForm1.WMHOTKEY(var Msg:TMessage); var h:HWND; buffer:array[0..256] of char; temp:String; begin if (Msg.LParamHi=KeyId) and (Msg.LParamLo=control) then begin Msg.Result:=1; h:=GetForegroundWindow; GetClassName(h,buffer,255); if StrPas(buffer)='IEFrame' then begin EnumChildWindows(h,@EnumChildWindowsProc,0); GetWindowText(h,buffer,255); buffer[Pos(' - ',buffer)]:=Char(0); temp:='当前网页的URL是:'+ThisUrl+#13#10+'当前网页Title是:'+buffer; MessageBox(h,PChar(temp),'提示信息',MB_OK) end; end; end;procedure TForm1.FormCreate(Sender: TObject); begin ThisUrl:=StrAlloc(250); control:=MOD_CONTROL or MOD_SHIFT ;KeyId:=$43; hotkeyid:=GlobalAddAtom('UserDefineHotKey')-$C000; RegisterHotKey(Handle,hotkeyid,control,KeyId); end;procedure TForm1.FormDestroy(Sender: TObject); begin UnregisterHotKey(Handle,hotkeyid); DeleteAtom(hotkeyid); end;end.
var
ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i: integer;
vi: OleVariant;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
begin
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count; for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
spDisp.QueryInterface( iWebBrowser2, IE1 );
if IE1 <> nil then
begin
memo1.Lines.Add( 'Location: '+ie1.LocationName ); IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin
memo1.Lines.add( 'Title: ' + IDOC1.Title );
memo1.Lines.add( 'Url: ' + IDOC1.url);
end;
end;
end;
end;
unit ligwin1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
control,KeyId:integer;
hotkeyid:ATOM;
public
{ Public declarations }
procedure WMHOTKEY(var Msg:TMessage);message WM_HOTKEY;
end;var
Form1: TForm1;
ThisUrl:PChar;implementation{$R *.DFM}
function EnumChildWindowsProc(H:HWnd;lparam:longint):Boolean;stdcall;
var
Buffer: array[0..10] of Char;
begin
Result:=True;
GetClassName(h,buffer,10);
if trim(StrPas(Buffer))='Edit' then
begin
SendMessage(h,WM_GETTEXT,249,Integer(ThisUrl));
Result:=False;
end;
end;procedure TForm1.WMHOTKEY(var Msg:TMessage);
var
h:HWND;
buffer:array[0..256] of char;
temp:String;
begin
if (Msg.LParamHi=KeyId) and (Msg.LParamLo=control) then
begin
Msg.Result:=1;
h:=GetForegroundWindow;
GetClassName(h,buffer,255);
if StrPas(buffer)='IEFrame' then
begin
EnumChildWindows(h,@EnumChildWindowsProc,0);
GetWindowText(h,buffer,255);
buffer[Pos(' - ',buffer)]:=Char(0);
temp:='当前网页的URL是:'+ThisUrl+#13#10+'当前网页Title是:'+buffer;
MessageBox(h,PChar(temp),'提示信息',MB_OK)
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ThisUrl:=StrAlloc(250);
control:=MOD_CONTROL or MOD_SHIFT ;KeyId:=$43;
hotkeyid:=GlobalAddAtom('UserDefineHotKey')-$C000;
RegisterHotKey(Handle,hotkeyid,control,KeyId);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle,hotkeyid);
DeleteAtom(hotkeyid);
end;end.
我不是要得到ie中的当前网址,
我的意思是要解析html文本,得到url
1.通过MSHTML封装的COM接口
2.自己编写HTML解析引擎要哪种?http://renzhen.org/article/list.asp?id=187
听说BOOST里面的那个REG什么的处理表达式的都比PERL的慢。
就是不知道怎么提取原代码!哈哈做个记号。
规范的,IE的兼容性好,也能显示出来,但是你自己做,也想做到这样高的兼容性可不太容易。
以FlashGet为例,装完后其中的文件jc_all.htm,就是用来提取所有网页上链接的。对应命令是使用网际快车下载全部链接,jc_link.htm用来提取当前链接,对就命令是使用网际快车下载。
首页,它的连接属性是http://www.csdn.net
楼主问的是如何得到http://www.csdn.net!
不过我转到WIN里面去看了一下,编译好大,160K左右
void parser(const std::string& fromfile,std::list<std::string>& slist)
注册邮箱 - http://members.sina.com.cn/apply/
企业邮箱 - http://mail.sina.net/
首页 - http://www.sina.com.cn/
新闻 - http://news.sina.com.cn/
娱乐 - http://ent.sina.com.cn/
游戏 - http://games.sina.com.cn/
男性 - http://man.sina.com.cn/
宠物 - http://bj.sina.com.cn/pet/
旅游 - http://travel.sina.com.cn/
文化 - http://cul.sina.com.cn/
邮箱 - http://mailhome.sina.com.cn/
北京 - http://bj.sina.com.cn/
同学录 - http://viafriend.sina.com.cn/
企业 - http://www.sina.net/
短信 - http://sms.sina.com.cn/
搞笑 - http://sms.sina.com.cn/docs/c/fcxh.html?from=425
体育 - http://sports.sina.com.cn/
搜索 - http://search.sina.com.cn/
无线 - http://wireless.sina.com.cn/
军事 - http://jczs.sina.com.cn/
女性 - http://eladies.sina.com.cn/
星座 - http://astro.sina.com.cn/
城市 - http://city.sina.net/
读书 - http://book.sina.com.cn/
饮食 - http://eat.sina.com.cn/
上海 - http://sh.sina.com.cn/
高尔夫 - http://golf.sina.com.cn/
招商 - http://gov.sina.net/
订阅 - http://sms.sina.com.cn/ringtone/custom.shtml
图片 - http://sms.sina.com.cn/ringtone/piclist.shtml
科技 - http://tech.sina.com.cn/
汽车 - http://auto.sina.com.cn/
培训 - http://edu.sina.com.cn/el/
留学 - http://edu.sina.com.cn/a/index.shtml
英语 - http://edu.sina.com.cn/en/index.shtml
育儿 - http://baby.sina.com.cn/
贺卡 - http://ecards.sina.com.cn/
动漫 - http://comic.sina.com.cn/
笑话 - http://newbbs4.sina.com.cn/index.shtml?living:xiaohua
广东 - http://gd.sina.com.cn/
下载区 - http://tech.sina.com.cn/down/
黄页 - http://yp.sina.net/
交友 - http://love.meme.com.cn/
铃声 - http://sms.sina.com.cn/ringtone/ringtone.shtml
财经 - http://finance.sina.com.cn/
房产 - http://housing.sina.com.cn/
教育 - http://edu.sina.com.cn/
出国 - http://edu.sina.com.cn/m/
健康 - http://511511.sina.com.cn/
商城 - http://mall.sina.com.cn/
天气 - http://weather.sina.com.cn/
论坛 - http://people.sina.com.cn/forum.html
聊天 - http://chat.sina.com.cn/
扬州 - http://yz.sina.com.cn/
嘉 宾 - http://people.sina.com.cn/guest/
分类 - http://classad.sina.com.cn/
星梦 - http://yoyorock.sina.com.cn/
彩信 - http://mms.sina.com.cn/
北京大学英语自考部招生 - http://sina.allyes.com/main/adfclick?db=sina&bid=810,3934,3950&cid=0,0,0&sid=4094&show=ignore&url=http://shangguang.longsu.net/beida/
中科院在职研究生(秋季) - http://sina.allyes.com/main/adfclick?db=sina&bid=20,49,49&cid=0,0,0&sid=49&show=ignore&url=http://www.edu-china.cn
首都高校扩招! - http://sina.allyes.com/main/adfclick?db=sina&bid=367,1180,1181&cid=0,0,0&sid=1211&show=ignore&url=http://www.bydsoft.com/
中国管理软件学院 - http://sina.allyes.com/main/adfclick?db=sina&bid=16,34,34&cid=0,0,0&sid=34&url=http://www.aa55.com/index.asp&show=ignore
欧园TWO HOUSE现房登场! - http://sina.allyes.com/main/adfclick?db=sina&bid=370,1190,1191&cid=0,0,0&sid=1221&show=ignore&url=http://www.beiouyinxiang.com
北大经理人班 CFO班 - http://sina.allyes.com/main/adfclick?db=sina&bid=16,36,36&cid=0,0,0&sid=36&url=http://econ.yp.sina.net/&show=ignore
万柳精装小户型