Calling Internet Explore from MATLAB and same also for FireFox too

4 次查看(过去 30 天)
Does anyone know how Calling Internet Explore from MATLAB and same also for FireFox too? and how reading an .html by them

采纳的回答

Kaustubha Govind
Kaustubha Govind 2011-9-23
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 个评论
Kaustubha Govind
Kaustubha Govind 2014-4-4
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 2014-4-7
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

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by