Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - Scaricare una pagina web in una variabile
Forum - Visual Basic 6 - Scaricare una pagina web in una variabile

Avatar
gvigliani (Normal User)
Pro


Messaggi: 105
Iscritto: 30/12/2006

Segnala al moderatore
Postato alle 19:09
Martedý, 05/05/2020
Buona sera,
lo so che Ŕ un discorso vecchio ed in effetti non ho problemi nello scaricare il sorgente da una qualsiasi web page ma da una in particolare.  Ovvero, fino a ieri ci riuscivo senza problemi ma da oggi mi scarica solo un trafiletto in cui mi si dice Accesso negato.  Pero', se entro in un browser e clicco su visualizza sorgente me lo fa fare senza problemi.
Quello di seguito Ŕ il codice che utilizzo per scaricare la pagina ma ho anche provato a scaricare con altri codici e sempre con lo stesso problema.

Codice sorgente - presumibilmente VB.NET

  1. Public Sub carica_sito(url)
  2. Info.Text = "Caricamento dati on line"
  3. On Error Resume Next
  4.     Dim hOpen               As Long
  5.     Dim hOpenUrl            As Long
  6.     Dim sURL                As String
  7.     Dim bDoLoop             As Boolean
  8.     Dim bRet                As Boolean
  9.     Dim sReadBuffer         As String * 2048
  10.     Dim lNumberOfBytesRead  As Long
  11.     Sbuffer = ""
  12.     sURL = url
  13.     Call DeleteUrlCacheEntry(url)
  14.     hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  15.     hOpenUrl = InternetOpenUrl(hOpen, sURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
  16.     bDoLoop = True
  17.     While bDoLoop
  18.         DoEvents
  19.         sReadBuffer = vbNullString
  20.         bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
  21.         Sbuffer = Sbuffer & Left$(sReadBuffer, lNumberOfBytesRead)
  22.         If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
  23.     Wend
  24.     If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
  25.     If hOpen <> 0 Then InternetCloseHandle (hOpen)
  26.     Info.Text = "Processo terminato"
  27.  
  28. End Sub




Tutto quello che mi ritrovo nella variabile Sbuffer Ŕ il seguente codice html:
Codice sorgente - presumibilmente Visual Basic 6

  1. <HTML><HEAD>
  2. <TITLE>Access Denied</TITLE>
  3. </HEAD><BODY>
  4. <H1>Access Denied</H1>
  5.  
  6. You don't have permission to access "http://it.soccerway.com/national/italy/serie-a/20192020/regular-season/r54890/matches/?" on this server.<P>
  7. Reference #18.6e2b1102.1588698335.500fd83
  8. </BODY>
  9. </HTML>



Il sito non richiede Id e passworddi accesso ed Ŕ:
https://it.soccerway.com

Sapete darmi una risposta?
Grazie

PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6276
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 19:30
Martedý, 05/05/2020
Hai usato una variabile scUserAgent che non ha valore.

Senza useragent non potrai accedere al sito


Ricorda che nessuno Ŕ obbligato a risponderti e che nessuno Ŕ perfetto ...
---
Il grande studioso italiano Bruno de Finetti (uno dei padri fondatori del moderno Calcolo delle probabilitÓ) chiamava il gioco del Lotto Tassa sulla stupiditÓ.
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1066
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 15:28
Mercoledý, 06/05/2020
Ho incollato il tuo codice in un progetto VB6, la variabile sBuffer si riempie con tutto l'HTML.
Non ho analizzato, ma con questo sistema ti perderai tutto l'HTML che si crea dinamicamente.
Codice sorgente - presumibilmente VB.NET

  1. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  2. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
  3. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
  4. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
  5. Private Declare Function DeleteUrlCacheEntry Lib "WININET" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
  6.  
  7.     Private Sub Form_Load()
  8.          carica_sito ("https://it.soccerway.com")
  9.     End Sub
  10.  
  11.  
  12.     Public Sub carica_sito(url)
  13.     Info.Text = "Caricamento dati on line"
  14.     On Error Resume Next
  15.         Dim hOpen               As Long
  16.         Dim hOpenUrl            As Long
  17.         Dim sURL                As String
  18.         Dim bDoLoop             As Boolean
  19.         Dim bRet                As Boolean
  20.         Dim sReadBuffer         As String * 2048
  21.         Dim lNumberOfBytesRead  As Long
  22.         sBuffer = ""
  23.         sURL = url
  24.         Call DeleteUrlCacheEntry(url)
  25.         hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  26.         hOpenUrl = InternetOpenUrl(hOpen, sURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
  27.         bDoLoop = True
  28.         While bDoLoop
  29.             DoEvents
  30.             sReadBuffer = vbNullString
  31.             bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
  32.             sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
  33.             If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
  34.         Wend
  35.         If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
  36.         If hOpen <> 0 Then InternetCloseHandle (hOpen)
  37.         Info.Text = "Processo terminato"
  38.         Text1.Text = sBuffer
  39.      
  40.     End Sub



Questo Ŕ quello che trovo in sBuffer:

Codice sorgente - presumibilmente Visual Basic 6

  1. <!DOCTYPE html>
  2. <html lang="it">
  3. <head>
  4.   <meta charset="utf-8" /><script type="text/javascript">(window.NREUM||(NREUM={})).loader_config={licenseKey:"dddd82eb94",applicationID:"197862323"};window.NREUM||(NREUM={}),__nr_require=function(e,n,t){function r(t){if(!n[t]){var i=n[t]={exports:{}};e[t][0].call(i.exports,function(n){var i=e[t][1][n];return r(i||n)},i,i.exports)}return n[t].exports}if("function"==typeof __nr_require)return __nr_require;for(var i=0;i<t.length;i++)r(t[i]);return r}({1:[function(e,n,t){function r(){}function i(e,n,t){return function(){return o(e,[u.now()].concat(f(arguments)),n?null:this,t),n?void 0:this}}var o=e("handle"),a=e(4),f=e(5),c=e("ee").get("tracer"),u=e("loader"),s=NREUM;"undefined"==typeof window.newrelic&&(newrelic=s);var p=["setPageViewName","setCustomAttribute","setErrorHandler","finished","addToTrace","inlineHit","addRelease"],l="api-",d=l+"ixn-";a(p,function(e,n){s[n]=i(l+n,!0,"api")}),s.addPageAction=i(l+"addPageAction",!0),s.setCurrentRouteName=i(l+"routeName",!0),n.exports=newrelic,s.interaction=function(){return(new r).get()};var m=r.prototype={createTracer:function(e,n){var t={},r=this,i="function"==typeof n;return o(d+"tracer",[u.now(),e,t],r),function(){if(c.emit((i?"":"no-")+"fn-start",[u.now(),r,i],t),i)try{return n.apply(this,arguments)}catch(e){throw c.emit("fn-err",[arguments,this,e],t),e}finally{c.emit("fn-end",[u.now()],t)}}}};a("actionText,setName,setAttribute,save,ignore,onEnd,getContext,end,get".split(","),function(e,n){m[n]=i(d+n)}),newrelic.noticeError=function(e,n){"string"==typeof e&&(e=new Error(e)),o("err",[e,u.now(),!1,n])}},{}],2:[function(e,n,t){function r(e,n){var t=e.getEntries();t.forEach(function(e){"first-paint"===e.name?c("timing",["fp",Math.floor(e.startTime)]):"first-contentful-paint"===e.name&&c("timing",["fcp",Math.floor(e.startTime)])})}function i(e,n){var t=e.getEntries();t.length>0&&c("lcp",[t[t.length-1]])}function o(e){if(e instanceof s&&!l){var n,t=Math.round(e.timeStamp);n=t>1e12?Date.now()-t:u.now()-t,l=!0,c("timing",["fi",t,{type:e.type,fid:n}])}}if(!("init"in NREUM&&"page_view_timing"in NREUM.init&&"enabled"in NREUM.init.page_view_timing&&NREUM.init.page_view_timing.enabled===!1)){var a,f,c=e("handle"),u=e("loader"),s=NREUM.o.EV;if("PerformanceObserver"in window&&"function"==typeof window.PerformanceObserver){a=new PerformanceObserver(r),f=new PerformanceObserver(i);try{a.observe({entryTypes:["paint"]}),f.observe({entryTypes:["largest-contentful-paint"]})}catch(p){}}if("addEventListener"in document){var l=!1,d=["click","keydown","mousedown","pointerdown","touchstart"];d.forEach(function(e){document.addEventListener(e,o,!1)})}}},{}],3:[function(e,n,t){function r(e,n){if(!i)return!1;if(e!==i)return!1;if(!n)return!0;if(!o)return!1;for(var t=o.split("."),r=n.split("."),a=0;a<r.length;a++)if(r[a]!==t[a])return!1;return!0}var i=null,o=null,a=/Version\/(\S+)\s+Safari/;if(navigator.userAgent){var f=navigator.userAgent,c=f.match(a);c&&f.indexOf("Chrome")===-1&&f.indexOf("Chromium")===-1&&(i="Safari",o=c[1])}n.exports={agent:i,version:o,match:r}},{}],4:[function(e,n,t){function r(e,n){var t=[],r="",o=0;for(r in e)i.call(e,r)&&(t[o]=n(r,e[r]),o+=1);return t}var i=Object.prototype.hasOwnProperty;n.exports=r},{}],5:[function(e,n,t){function r(e,n,t){n||(n=0),"undefined"==typeof t&&(t=e?e.length:0);for(var r=-1,i=t-n||0,o=Array(i<0?0:i);++r<i;)o[r]=e[n+r];return o}n.exports=r},{}],6:[function(e,n,t){n.exports={exists:"undefined"!=typeof window.performance&&window.performance.timing&&"undefined"!=typeof window.performance.timing.navigationStart}},{}],ee:[function(e,n,t){function r(){}function i(e){function n(e){return e&&e instanceof r?e:e?c(e,f,o):o()}function t(t,r,i,o){if(!l.aborted||o){e&&e(t,r,i);for(var a=n(i),f=v(t),c=f.length,u=0;u<c;u++)f[u].apply(a,r);var p=s[y[t]];return p&&p.push([b,t,r,a]),a}}function d(e,n){h[e]=v(e).concat(n)}function m(e,n){var t=h[e];if(t)for(var r=0;r<t.length;r++)t[r]===n&&t.splice(r,1)}function v(e){return h[e]||[]}function g(e){return p[e]=p[e]||i(t)}function w(e,n){u(e,function(e,t){n=n||"feature",y[t]=n,n in s||(s[n]=[])})}var h={},y={},b={on:d,addEventListener:d,removeEventListener:m,emit:t,get:g,listeners:v,context:n,buffer:w,abort:a,aborted:!1};return b}function o(){return new r}function a(){(s.api||s.feature)&&(l.aborted=!0,s=l.backlog={})}var f="nr@context",c=e("gos"),u=e(4),s={},p={},l=n.exports=i();l.backlog=s},{}],gos:[function(e,n,t){function r(e,n,t){if(i.call(e,n))return e[n];var r=t();if(Object.defineProperty&&Object.keys)try{return Object.defineProperty(e,n,{value:r,writable:!0,enumerable:!1}),r}catch(o){}return e[n]=r,r}var i=Object.prototype.hasOwnProperty;n.exports=r},{}],handle:[function(e,n,t){function r(e,n,t,r){i.buffer([e],r),i.emit(e,n,t)}var i=e("ee").get("handle");n.exports=r,r.ee=i},{}],id:[function(e,n,t){function r(e){var n=typeof e;return!e||"object"!==n&&"function"!==n?-1:e===window?0:a(e,o,function(){return i++})}var i=1,o="nr@id",a=e("gos");n.exports=r},{}],loader:[function(e,n,t){function r(){if(!x++){var e=E.info=NREUM.info,n=d.getElementsByTagName("script")[0];if(setTimeout(s.abort,3e4),!(e&&e.licenseKey&&e.applicationID&&n))return s.abort();u(y,function(n,t){e[n]||(e[n]=t)}),c("mark",["onload",a()+E.offset],null,"api");var t=d.createElement("script");t.src="https://"+e.agent,n.parentNode.insertBefore(t,n)}}function i(){"complete"===d.readyState&&o()}function o(){c("mark",["domContent",a()+E.offset],null,"api")}function a(){return O.exists&&performance.now?Math.round(performance.now()):(f=Math.max((new Date).getTime(),f))-E.offset}var f=(new Date).getTime(),c=e("handle"),u=e(4),s=e("ee"),p=e(3),l=window,d=l.document,m="addEventListener",v="attachEvent",g=l.XMLHttpRequest,w=g&&g.prototype;NREUM.o={ST:setTimeout,SI:l.setImmediate,CT:clearTimeout,XHR:g,REQ:l.Request,EV:l.Event,PR:l.Promise,MO:l.MutationObserver};var h=""+location,y={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",agent:"js-agent.newrelic.com/nr-1167.min.js"},b=g&&w&&w[m]&&!/CriOS/.test(navigator.userAgent),E=n.exports={offset:f,now:a,origin:h,features:{},xhrWrappable:b,userAgent:p};e(1),e(2),d[m]?(d[m]("DOMContentLoaded",o,!1),l[m]("load",r,!1)):(d[v]("onreadystatechange",i),l[v]("onload",r)),c("mark",["firstbyte",f],null,"api");var x=0,O=e(6)},{}],"wrap-function":[function(e,n,t){function r(e){return!(e&&e instanceof Function&&e.apply&&!e[a])}var i=e("ee"),o=e(5),a="nr@original",f=Object.prototype.hasOwnProperty,c=!1;n.exports=function(e,n){function t(e,n,t,i){function nrWrapper(){var r,a,f,c;try{a=this,r=o(arguments),f="function"==typeof t?t(r,a):t||{}}catch(u){l([u,"",[r,a,i],f])}s(n+"start",[r,a,i],f);try{return c=e.apply(a,r)}catch(p){throw s(n+"err",[r,a,p],f),p}finally{s(n+"end",[r,a,c],f)}}return r(e)?e:(n||(n=""),nrWrapper[a]=e,p(e,nrWrapper),nrWrapper)}function u(e,n,i,o){i||(i="");var a,f,c,u="-"===i.charAt(0);for(c=0;c<n.length;c++)f=n[c],a=e[f],r(a)||(e[f]=t(a,u?f+i:i,o,f))}function s(t,r,i){if(!c||n){var o=c;c=!0;try{e.emit(t,r,i,n)}catch(a){l([a,t,r,i])}c=o}}function p(e,n){if(Object.defineProperty&&Object.keys)try{var t=Object.keys(e);return t.forEach(function(t){Object.defineProperty(n,t,{get:function(){return e[t]},set:function(n){return e[t]=n,n}})}),n}catch(r){l([r])}for(var i in e)f.call(e,i)&&(n[i]=e[i]);return n}function l(n){try{e.emit("internal-error",n)}catch(t){}}return e||(e=i),t.inPlace=u,t.flag=a,t}},{}]},{},["loader"]);</script>
  5. ........
  6. ........
  7. ........



ecc ecc non posto oltre l'html che Ŕ molto lungo

Ultima modifica effettuata da Carlo il 06/05/2020 alle 18:13


in programmazione tutto Ŕ permesso
PM Quote