the_bigboo | La fonction suivante te permet de récupérer un contenu HTML sans suivre de redirection :
Code :
- Uses Wininet;
- {----------------------------------------------------------------}
- Function GetHTML(AUrl: String): String;
- Var
- databuffer: Array[0..4095] Of Char;
- hSession, hfile: hInternet;
- dwindex, dwcodelen, dwread, dwNumber: Cardinal;
- dwcode: Array[1..20] Of Char;
- res: PChar;
- Begin
- Result := '';
- hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0);
- If (Assigned(hsession)) Then Begin
- hfile := InternetOpenUrl(hsession, PChar(AUrl), Nil, 0, INTERNET_FLAG_RELOAD, 0);
- dwIndex := 0;
- dwCodeLen := 10;
- HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
- res := pchar(@dwcode);
- dwNumber := SizeOf(databuffer) - 1;
- If ((res = '200') Or (res = '302')) Then Begin
- While (InternetReadfile(hfile, @databuffer, dwNumber, DwRead)) Do Begin
- If (dwRead = 0) Then Break;
- databuffer[dwread] := #0;
- Result := Result + PChar(@databuffer);
- End;
- End Else Result := 'Status:' + res;
- If (Assigned(hfile)) Then InternetCloseHandle(hfile);
- End;
- InternetCloseHandle(hsession);
- End;
- {----------------------------------------------------------------}
- Procedure TForm1.FormCreate(Sender: TObject);
- Begin
- Memo1.Text := GetHTML('http://forum.hardware.fr');
- End;
|
Apres , il existe des modules d'expressions régulieres PCRE compatibles Delphi qui te permettrai de récupérer les liens. Message édité par the_bigboo le 29-06-2006 à 22:21:16
|