Perform a web search through Matlab and get back the results
8 views (last 30 days)
Show older comments
Hello,
I would like to perform a search in a website (every time searching different terms) and get results in matlab platform.
Do you know any easy and reliable method to perform this?
Thanks in advance.
LK
0 Comments
Answers (1)
DGM
on 4 Apr 2023
Edited: DGM
on 4 Apr 2023
There are probably better ways, but here's one example I pulled from something else I wrote.
This relies on Google's JSON API. You'll need to read about how to set that up.
apikey = '12345'; % your API key
cx = '12345'; % your search engine ID
query = 'delicious spiders'; % the search query
wopt = weboptions('contenttype','json');
url = ['https://customsearch.googleapis.com/customsearch/v1?cx=' cx '&key=' apikey '&q=' query '&num=10'];
try
S = webread(url,wopt);
catch
% this might also happen if no exact url exist and API call is broken somehow
fprintf('Connection error. Web search failed.\n')
return;
end
Your results will be in the struct S.
Considering that getting relevant results from search engines is often difficult to impossible, I would posit that there is no such thing as a reliable option, regardless of how consistently they might execute without overt error.
0 Comments
See Also
Categories
Find more on JSON Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!