5,388
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.DomImg2Image(src:string;wb:TWebBrowser;img:TImage);
var
i:Integer;
rang:IHTMLControlRange;
begin
for i:=0 to IHTMLDocument2(wb.Document).images.length-1 do
begin
{yzm.Text:=(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as
IHTMLElement).getAttribute('src',0); }
if Pos(src,(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as
IHTMLElement).getAttribute('src',0))>0 then
begin
rang:=((IHTMLDocument2(wb.Document).body as HTMLBody).createControlRange)as
IHTMLControlRange;
rang.add(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as
IHTMLControlElement);
rang.execCommand('Copy',False,0);
try
img.Picture.Assign(ClipBoard);
//img.Picture.SaveToFile('C:\1.GIF');
except end;
break;
end;
end;
end;
uses WinINet;
Function TForm1.GetCacheVerifyCodeFile(VerifyCodeURL:String; Var CacheVerifyCodeFile:String):Boolean;
Var
lpEntryInfo: PInternetCacheEntryInfo;
dwEntrySize, dwLastError, Hwd: LongWORD;
i, j: Integer;
f: String;
Begin
Result := false;
dwEntrySize := 0;
j := 0;
CacheVerifyCodeFile := '';
FindFirstUrlCacheEntry(Nil, TInternetCacheEntryInfo(Nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);
Hwd := FindFirstUrlCacheEntry(Nil, lpEntryInfo^, dwEntrySize);
If Hwd <> 0 Then
Begin
Repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(Hwd, TInternetCacheEntryInfo(Nil^), dwEntrySize);
dwLastError := GetLastError();
If dwLastError = ERROR_INSUFFICIENT_BUFFER Then
Begin
GetMem(lpEntryInfo, dwEntrySize);
If FindNextUrlCacheEntry(Hwd, lpEntryInfo^, dwEntrySize) Then
begin
If Pos(UpperCase(VerifyCodeURL), UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 Then
Begin
i := FileAge(lpEntryInfo.lpszLocalFileName);
If i > j Then
Begin
j := i;
f := lpEntryInfo.lpszLocalFileName;
End
Else
DeleteUrlCacheEntry(lpEntryInfo.lpszSourceUrlName);
End;
end;
End;
Application.ProcessMessages;
Until (dwLastError = ERROR_NO_MORE_ITEMS);
If FileExists(f) Then
Begin
CacheVerifyCodeFile := f;
Result := true;
End;
End;
FreeMem(lpEntryInfo);
FindCloseUrlCache(Hwd);
End;
此函数有两个参数,第一个是网络图片地址,第二个是本地缓存地址。第二个作为输出端口。
我按这个代码写的
GetCacheVerifyCodeFile('http://auth.changyou.com/servlet/ImageCode',s);
ShowMessage(s);//取不到缓存地址