Calling Internet Explore from MATLAB and same also for FireFox too

4 views (last 30 days)
Does anyone know how Calling Internet Explore from MATLAB and same also for FireFox too? and how reading an .html by them

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 23 Sep 2011
Try:
myUrl = 'www.mathworks.com/index.html';
ieCmd = ['iexplore ' myUrl];
ffCmd = ['firefox ' myUrl];
system(ieCmd);
system(ffCmd);
Both iexplore.exe and firefox.exe should be on the system PATH variable.
  6 Comments
Kaustubha Govind
Kaustubha Govind on 4 Apr 2014
Perhaps iexplore.exe is not on your System PATH. You could right click on your desktop/Start menu Internet Explorer icon, select "Properties" to see the full path to the application.
Image Analyst
Image Analyst on 7 Apr 2014
I found the file here: C:/Program Files (x86)/Internet Explorer/iexplore.exe. Evidently that's not on the path, probably because it's a 32 bit program on a 64 bit computer. It works if I put in the full path. Just to be sure, I put in some Active X code to try if it fails to find it. Here is my final code:
myUrl = 'http://blah-whatever.com/statserver/R/default.asp';
iePath = '"C:/Program Files (x86)/Internet Explorer/iexplore.exe"';
if exist(iePath(2:end-1), 'file') % Don't include double quotes in the path we send to the exist() function or it won't find the file.
% Copy filename to the clipboard
clipboard('copy', excelFullFileName);
% Launch using the system() command.
ieCmd = sprintf('%s %s', iePath, myUrl);
system(ieCmd); % User pastes in filename when this page loads.
else
% Didn't find it. Try to let the system find it.
% Launch using CopyPasteIE() function which uses ActiveX to try to find it.
CopyPasteIE(myUrl)
end
Here's the ActiveX function:
% The following example uses the ACTXCONTROL command to call Internet Explorer.
% This function takes in a URL as a string, loads the URL in Internet Explorer, copies the text from the URL, and returns the copied text as a string for use inside of MATLAB.
% Reference is a web page on the Mathworks server:
% http://www.mathworks.com/matlabcentral/answers/92736-is-there-an-example-of-how-to-call-microsoft-internet-explorer-as-an-automation-server
% Note: The code provided in this example is for demonstration purposes and has not been thoroughly tested.
function str = CopyPasteIE(url)
try
str = [];
ha = actxserver('internetexplorer.application');
ha.Visible = 1;
Navigate(ha, url);
% pause(3); % Pause to let the page load
% ha.document.execCommand('selectall','','');
% ha.document.execCommand('copy','','');
% str=clipboard('paste');
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
WarnUser(errorMessage);
end
return; % from CopyPasteIE

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 23 Sep 2011
How about web() with -browser option.
help urlread

Community Treasure Hunt

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

Start Hunting!