time to access webpage
Mostrar comentarios más antiguos
I am trying to write a simple code which allows me to access a specific webpage at a very exact time (precise upon a few milliseconds). In the code below I use the variable 'timerbrow' as the time (in seconds) for the code and the browser to open the webpage. At the moment I have to guess this time manually. I was wondering if this time can be found automatically? For example by pinging the website through MatLab?
Thanks in advance
close all, clear all;
%%%give in time it takes for browser to load.
timerbrow=1;
runsec=60-timerbrow;
Dsec=1; Dminute=1;
while Dsec>0.001 && Dminute>0.001
c=clock;
Dminute=59-c(5);
Dsec=runsec-c(6);
end
%%%give in the url
url='https://www.google.com';
[stat,h]=web(url,'-browser');
4 comentarios
Rik
el 28 de En. de 2018
Why use the while loop, and not use a plain pause(runsec)?
Also, I don't understand what you want with respect to your timing.
The ping can be easily implemented with a call to system:
function [connected,timing]=get_response_time(url_or_ip)
if ispc
[~,b]=system(['ping -n 1 ' url_or_ip]);
n=strfind(b,'Lost');
n1=b(n+7);
if(n1=='0')
connected=1;
if nargout==2
n=strfind(b,'time=');m=strfind(b,'ms');m=m(m>n);m=m(1)-1;
timing=str2double(b((n+5):m));
end
else
connected=0;
timing=0;
end
elseif isunix
[~,b]=system(['ping -c 1 ' url_or_ip]);
n=strfind(b,'received');
n1=b(n-2);
if(n1=='1')
connected=1;
if nargout==2
n=strfind(b,'/');n=n([end-1 end]);
timing=str2double(b(n(1):n(2)));
end
else
connected=0;
timing=0;
end
else
error('How did you even get Matlab to work?')
end
(I use this to ping to 8.8.8.8 to see if there is an internet connection)
Hannes Wielant
el 28 de En. de 2018
Rik
el 28 de En. de 2018
A pause would do the same thing as your loop, but not use as much computational resources.
The time to load a page can be substantially more than just the ping. Just testing it might be the only solution.
Hannes Wielant
el 28 de En. de 2018
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 28 de En. de 2018
2 votos
The time to serve a web page is quite variable, and depends upon the amount of internet traffic between you and the host (for them to get the request) and upon the load they have right then (for them to process the request) and upon the amount of internet traffic back from them to you. Multiple hosts in very different locations can be involved depending on the exact request -- for example Mathworks uses one of the cloud hosting companies to provide faster response for some kinds of queries.
I suggest you have a look at http://hoaxes.org/weblog/comments/90_million_people_flush_toilet_during_superbowl_half_time for examples of usage peaks.
Your target probably cannot be reasonably met.
1 comentario
Hannes Wielant
el 29 de En. de 2018
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!