Jump to content


Photo

Extraer código fuente de web

codigo fuente source code web

Best Answer escafandra , 12 April 2022 - 01:55 PM

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. Go to the full post


  • Please log in to reply
2 replies to this topic

#1 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 posts

Posted 12 April 2022 - 06:38 AM

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
  • 4107 posts
  • LocationMadrid - España

Posted 12 April 2022 - 01:55 PM   Best Answer

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 posts

Posted 12 April 2022 - 02:21 PM

Funciona perfecto Escanfandra.

 

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


  • 0





Also tagged with one or more of these keywords: codigo fuente, source code, web

IP.Board spam blocked by CleanTalk.