Hi All
I am accessing a website that has a 'Loading screen' once it's all loaded the HTML is readable but every time I use webread it still returns only the 'Loading....' screen HTML.
I've tried going through the browser and setting the weboptions timeout higher but these haven't helped.
would be greatful if someone could point me to something i've missed.
Thanks

 Accepted Answer

Try putting webread in a while loop until it doesn't say that.
maxIterations = 10; % However long you want to wait
count = 1;
while count < maxIterations
pageContents = webread(......)
if ~contains(pageContents, 'Loading...')
% It's not loading anymore so we can quit calling webread().
break;
end
% Wait a little bit
pause(1); % Pause 1 second.
count = count + 1;
end

2 Comments

This is such a great answer, I got so far down the route of trying to solve it in one line of code I lost track of the wider picture.
Currently I've been using an active browser and reading the content after a delay but this is nicer.
Thanks so much.
You're welcome. You might want to add some code at the end like
if count >= maxIterations
% Never was able to load the web page. Warn the user.
warningMessage = sprintf('The web page was not returned after waiting %d seconds.', count);
uiwait(warndlg(warningMessage));
return; % Unless you can continue without it.
end

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!