Ir al contenido


Foto

Extraer código fuente de web

codigo fuente source code web

Mejor respuesta escafandra , 12 abril 2022 - 01:55

Prueba de esta manera:

delphi
  1. uses Wininet;
  2.  
  3.  
  4. function InternetReadWeb(URL: String): String;
  5. var
  6. hNet: pointer;
  7. hUrl: pointer ;
  8. Buffer: array [0..255] of char;
  9. BytesRead: DWORD;
  10. NoError: boolean;
  11. Ind: integer;
  12. begin
  13. BytesRead:= 0;
  14. Result:= '';
  15.  
  16. if InternetAttemptConnect(0) <> ERROR_SUCCESS then exit;
  17.  
  18. hNet:= InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  19. if hNet <> nil then
  20. begin
  21. hUrl:= InternetOpenUrl(hNet, PCHAR(URL), nil, 0, INTERNET_FLAG_RELOAD, 0);
  22. if hUrl <> nil then
  23. begin
  24. // Lee la pagina web...
  25. ind:=0;
  26. repeat
  27. NoError:= InternetReadFile(hUrl, @Buffer[0], sizeof(Buffer)-1, BytesRead);
  28. if NoError and (BytesRead = 0) then break;
  29. Buffer[BytesRead]:= #0;
  30. Result:= Result + String(Buffer);
  31. inc(ind, BytesRead);
  32. until NoError and (BytesRead=0);
  33. InternetCloseHandle(hUrl);
  34. end;
  35. InternetCloseHandle(hNet);
  36. end;
  37. end;
  38.  
  39. procedure TForm1.Button3Click(Sender: TObject);
  40. begin
  41. Memo1.Text:= InternetReadWeb('https://developers.google.com/search/docs/advanced/security/https?hl=es');
  42. end;

Saludos. Ir al mensaje completo


  • Por favor identifícate para responder
2 respuestas en este tema

#1 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 12 abril 2022 - 06:38

Hola como están:

 

Alguein tiene alguna función para extraer el código fuente de una página web.

 

Antes con un simple idhttp.get(URL) se optenía con direcciones http://

pero ahora con direcciones https:// esto no funciona.

 

alguna idea


  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 12 abril 2022 - 01:55   Mejor respuesta

Prueba de esta manera:

delphi
  1. uses Wininet;
  2.  
  3.  
  4. function InternetReadWeb(URL: String): String;
  5. var
  6. hNet: pointer;
  7. hUrl: pointer ;
  8. Buffer: array [0..255] of char;
  9. BytesRead: DWORD;
  10. NoError: boolean;
  11. Ind: integer;
  12. begin
  13. BytesRead:= 0;
  14. Result:= '';
  15.  
  16. if InternetAttemptConnect(0) <> ERROR_SUCCESS then exit;
  17.  
  18. hNet:= InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  19. if hNet <> nil then
  20. begin
  21. hUrl:= InternetOpenUrl(hNet, PCHAR(URL), nil, 0, INTERNET_FLAG_RELOAD, 0);
  22. if hUrl <> nil then
  23. begin
  24. // Lee la pagina web...
  25. ind:=0;
  26. repeat
  27. NoError:= InternetReadFile(hUrl, @Buffer[0], sizeof(Buffer)-1, BytesRead);
  28. if NoError and (BytesRead = 0) then break;
  29. Buffer[BytesRead]:= #0;
  30. Result:= Result + String(Buffer);
  31. inc(ind, BytesRead);
  32. until NoError and (BytesRead=0);
  33. InternetCloseHandle(hUrl);
  34. end;
  35. InternetCloseHandle(hNet);
  36. end;
  37. end;
  38.  
  39. procedure TForm1.Button3Click(Sender: TObject);
  40. begin
  41. Memo1.Text:= InternetReadWeb('https://developers.google.com/search/docs/advanced/security/https?hl=es');
  42. end;

Saludos.
  • 1

#3 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 12 abril 2022 - 02:21

Funciona perfecto Escanfandra.

 

Gracias por la función.. Un saludo,.


  • 0





Etiquetado también con una o más de estas palabras: codigo fuente, source code, web

IP.Board spam blocked by CleanTalk.