如何为webbrowser设置超时 我打算利用 Webbrowser对一批URL进行存在性检测,但有一些URL是不存在的,请问在delphi中,WEBBrowser如何设置超时的时间?我想如果3秒没有反应就跳过去。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用它来进行URL检查太麻烦了吧。function CheckUrl(const S: String): Boolean;var hSession, hfile: hInternet; dwindex,dwcodelen: dword; dwcode: array[1..20] of char; res: pchar; url:String;begin url:=S; if pos('http://',lowercase(url)) = 0 then url := 'http://' + url; Result := false; hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,nil, nil, 0); if assigned(hsession) then begin hfile := InternetOpenUrl( hsession, pchar(url), nil, 0, INTERNET_FLAG_RELOAD, 0); dwIndex := 0; dwCodeLen := 10; HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex); res := pchar(@dwcode); result := (res = '200') or (res = '302'); if assigned(hfile) then InternetCloseHandle(hfile); InternetCloseHandle(hsession); end;end; 忘记说一个要求了。除了验证这个URL是否存在外,还需要判断这个 URL 是否包含特定的字符串。如果有才可用, 如果没有, 不能用。 單純檢測網址建議用Tidhttpvar httpget:Tidhttp;begin HttpGet:= TIdhttp.Create(nil); HttpGet.ReadTimeout:= 30000;(超時30秒) HttpGet.get('http://www'); ... httpget.free; 用它:ansicontainsstr(網址,'特定字符串') 返回boolean 楼上的师兄。我用IDhttp,GEt出来的网页源码,怎么会有乱码呢(据说是utf-16还是什么的)?以下是我原来写的Get的函数。Function TCheckThread.GetWebPage(const Url: string):string;var Session, HttpFile:HINTERNET; szSizeBuffer:Pointer; dwLengthSizeBuffer:DWord; dwReserved:DWord; dwFileSize:DWord; dwBytesRead:DWord; Contents:PChar; TimeOut:Integer;begin TimeOut:=5000; //设置超时时间 try InternetSetOption(Session, Internet_OPTION_CONNECT_TIMEOUT, @TimeOut, 4); Session:=InternetOpen('Mozilla/4.0',INTERNET_OPEN_TYPE_PRECONFIG,niL,niL,0); HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0); dwLengthSizeBuffer:=1024; HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved); GetMem(Contents,dwFileSize); InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead); InternetCloseHandle(HttpFile); InternetCloseHandle(Session); Result:=StrPas(Contents); FreeMem(Contents); Except End;End;另外如果这个函数放在多线程里面,怎么确保Get到HTML:在单线程的环境里,可以取到源代码,但在多线程里面好像不行。我想知道怎么知道IDhttp下载网页源码完毕了? 如果是在多線程中,且線程只有這個動作的話。下載完畢就會就線程結束所以FreeOnTerminate := true; 后就可以用OnTerminate:= 事件來告訴你已下載完畢! 我的问题是线程里面好像没有等待取到html的源码,而直接就跳过去了。如何在子线程里面一直等待到 httpget 完成取得网页源码的动作后,才进行下一步。 还是comboboxd的问题 DBComboBox的Text为什么是空值?请高手指点! 求delphi7的参考资料 ado中Filter的疑问 在delphi关于动态打印的问题? FLASH右键菜单怎么屏蔽? 奇怪的问题!在菜单中加入快捷键,在执行时快捷键显示不全!!! 如何实现 关于COM 和 TApplication(Forms单元,来者有分,不够再加分) 急求、过虑(含变量的)字符串! 两个问题 随便一问:ADOQuery在open后,能否取其中的某些字段的最大值?
var
hSession, hfile: hInternet;
dwindex,dwcodelen: dword;
dwcode: array[1..20] of char;
res: pchar;
url:String;
begin
url:=S;
if pos('http://',lowercase(url)) = 0 then
url := 'http://' + url;
Result := false;
hSession := InternetOpen('InetURL:/1.0',
INTERNET_OPEN_TYPE_PRECONFIG,nil, nil, 0);
if assigned(hsession) then
begin
hfile := InternetOpenUrl(
hsession,
pchar(url),
nil,
0,
INTERNET_FLAG_RELOAD,
0);
dwIndex := 0;
dwCodeLen := 10;
HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE,
@dwcode, dwcodeLen, dwIndex);
res := pchar(@dwcode);
result := (res = '200') or (res = '302');
if assigned(hfile) then
InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;
var
httpget:Tidhttp;
begin HttpGet:= TIdhttp.Create(nil);
HttpGet.ReadTimeout:= 30000;(超時30秒)
HttpGet.get('http://www');
... httpget.free;
var
Session,
HttpFile:HINTERNET;
szSizeBuffer:Pointer;
dwLengthSizeBuffer:DWord;
dwReserved:DWord;
dwFileSize:DWord;
dwBytesRead:DWord;
Contents:PChar;
TimeOut:Integer;
begin
TimeOut:=5000; //设置超时时间
try
InternetSetOption(Session, Internet_OPTION_CONNECT_TIMEOUT, @TimeOut, 4);
Session:=InternetOpen('Mozilla/4.0',INTERNET_OPEN_TYPE_PRECONFIG,niL,niL,0);
HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
dwLengthSizeBuffer:=1024;
HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
GetMem(Contents,dwFileSize);
InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result:=StrPas(Contents);
FreeMem(Contents);
Except
End;
End;
另外如果这个函数放在多线程里面,怎么确保Get到HTML:在单线程的环境里,可以取到源代码,但在多线程里面好像不行。我想知道怎么知道IDhttp下载网页源码完毕了?