如何用delphi提取html文件中的内容???(急) 如何用delphi提取html文件中的内容??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个问题比较好解决,首先你要先获得html页面内的信息在indy组件中,好在有一个idHttp的组建,使用这个对象的get方法,就可以获取到页面信息源代码注意,这些信息将保存在一个string类型的字符串里面。解析这些信息就可以了 to : blastodermx(柏拉图的迷茫)说的容易做起来难啊,解析,呵呵 高手们写的函数:function HttpRequestExecute(const URL, QureyData: string): string;var hSession, hConnect, hRequest: hInternet; RequestMethod, TempStr, HostName, FileName: string; BytesToRead : cardinal; DataLength : integer; AData : array[0..40960] of char; InternetFlag : LongWord; AcceptType : PAnsiChar; Buf : array[0..1023] of char; dwBufLen, dwIndex: LongWord; procedure ParseURL(URL: string; var HostName, FileName: string); var i : Integer; begin if Pos('http://', URL) <> 0 then System.Delete(URL, 1, 7); i := Pos('/', URL); HostName := Copy(URL, 1, i); FileName := Copy(URL, i, Length(URL) - i + 1); if (Length(HostName) > 0) and (HostName[Length(HostName)] = '/') then SetLength(HostName, Length(HostName) - 1); end; procedure CloseHandles; begin InternetCloseHandle(hRequest); InternetCloseHandle(hConnect); InternetCloseHandle(hSession); end;begin result := ''; ParseURL(URL, HostName, FileName); hSession := InternetOpen(PChar(''), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); hConnect := InternetConnect(hSession, PChar(HostName), INTERNET_DEFAULT_HTTP_PORT, '', '', INTERNET_SERVICE_HTTP, 0, 0); if QureyData = '' then RequestMethod := 'GET' else RequestMethod := 'POST'; InternetFlag := 0; AcceptType := PChar('Accept: */*'); hRequest := HttpOpenRequest(hConnect, PChar(RequestMethod), PChar(FileName), 'HTTP/1.0', '', @AcceptType, InternetFlag, 0); if QureyData = '' then HttpSendRequest(hRequest, nil, 0, nil, 0) else HttpSendRequest(hRequest, 'Content-Type: application/x-www-form-urlencoded', 47, PChar(QureyData), Length(QureyData)); BytesToRead := 0; dwIndex := 0; dwBufLen := sizeof(Buf); HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH, @Buf, dwBufLen, dwIndex); DataLength := StrToIntDef(Buf, 0); while InternetReadFile(hRequest, @AData, SizeOf(AData), BytesToRead) do begin if BytesToRead = 0 then break; SetString(TempStr, AData, BytesToRead); Result := Result + TempStr; end; CloseHandles;end;使用时:memo2.Lines.Text :=HttpRequestExecute(edit1.Text ,'') ; 放入IdHttp控件mStr :String;url: 网址mStr := IdHttp1.Get(url); 请问在客户端不装delphi如何快速安装配置好bde? 关于插入的一个问题 感谢kl2000,接分! fastreport打印问题 tlink=^note; //运行时出现(Expected':' but'='found)怎样解决 在数据模块中调用另一窗体(非自动创建)中的过程,请教! 怎样把integer类型直接转换为real类型啊? CXGRID如何对单元格多选求和 在WINDOWS平台中,在许多的应用软件的相互切换过程中,我怎样才能知到我的应用程序处于激活状态? 如果您是陈盈豪,那就小Kiss了???(500分) 弱问: 有关dxTreeList 求助一个简单activex的例子!
在indy组件中,好在有一个idHttp的组建,使用这个对象的get方法,就可以获取到页面信息
源代码注意,这些信息将保存在一个string类型的字符串里面。解析这些信息就可以了
说的容易做起来难啊,解析,呵呵
function HttpRequestExecute(const URL, QureyData: string): string;
var
hSession, hConnect, hRequest: hInternet;
RequestMethod, TempStr, HostName, FileName: string;
BytesToRead : cardinal;
DataLength : integer;
AData : array[0..40960] of char;
InternetFlag : LongWord;
AcceptType : PAnsiChar;
Buf : array[0..1023] of char;
dwBufLen, dwIndex: LongWord;
procedure ParseURL(URL: string; var HostName, FileName: string);
var
i : Integer;
begin
if Pos('http://', URL) <> 0 then
System.Delete(URL, 1, 7);
i := Pos('/', URL);
HostName := Copy(URL, 1, i);
FileName := Copy(URL, i, Length(URL) - i + 1);
if (Length(HostName) > 0) and (HostName[Length(HostName)] = '/') then
SetLength(HostName, Length(HostName) - 1);
end;
procedure CloseHandles;
begin
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
end;
begin
result := '';
ParseURL(URL, HostName, FileName);
hSession := InternetOpen(PChar(''),
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
hConnect := InternetConnect(hSession, PChar(HostName),
INTERNET_DEFAULT_HTTP_PORT, '', '', INTERNET_SERVICE_HTTP, 0, 0);
if QureyData = '' then RequestMethod := 'GET'
else RequestMethod := 'POST';
InternetFlag := 0;
AcceptType := PChar('Accept: */*');
hRequest := HttpOpenRequest(hConnect, PChar(RequestMethod), PChar(FileName), 'HTTP/1.0',
'', @AcceptType, InternetFlag, 0);
if QureyData = '' then
HttpSendRequest(hRequest, nil, 0, nil, 0)
else
HttpSendRequest(hRequest, 'Content-Type: application/x-www-form-urlencoded', 47,
PChar(QureyData), Length(QureyData));
BytesToRead := 0;
dwIndex := 0;
dwBufLen := sizeof(Buf);
HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH, @Buf, dwBufLen, dwIndex);
DataLength := StrToIntDef(Buf, 0);
while InternetReadFile(hRequest, @AData, SizeOf(AData), BytesToRead) do
begin
if BytesToRead = 0 then break;
SetString(TempStr, AData, BytesToRead);
Result := Result + TempStr;
end;
CloseHandles;
end;使用时:
memo2.Lines.Text :=HttpRequestExecute(edit1.Text ,'') ;
mStr :String;
url: 网址
mStr := IdHttp1.Get(url);