"webread" does not work for Yahoo Option Chains page
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cengiz Esmersoy
el 4 de Ag. de 2024 a las 21:41
Respondida: Kanishk
el 13 de Ag. de 2024 a las 10:44
Going to any Yahoo Option Chain page, copy and paste the URL to webread returns an error. For example:
webread('https://finance.yahoo.com/quote/AAPL/options/')
returns
The server returned the status 404 with message "Not Found"
It works for stock prices, but not for option chains. Is this a Yahoo protection issue or a limitation of webread?
3 comentarios
Cengiz Esmersoy
el 5 de Ag. de 2024 a las 20:43
Editada: Cengiz Esmersoy
el 5 de Ag. de 2024 a las 20:44
Walter Roberson
el 6 de Ag. de 2024 a las 3:02
Access blocks would typically be error 403, Access Prohibitted.
Respuestas (1)
Kanishk
el 13 de Ag. de 2024 a las 10:44
Hi Cengiz,
It seems that when trying to use ‘webread’ to access the Yahoo Finance options page ‘404 Not Found’ error is encountered.
The issue appears to be related to the "User-Agent" field in the HTTP request. Some servers, including Yahoo Finance, selectively block requests from certain clients if the "User-Agent" field is not set or is set to an unrecognized value.
Although the field is not mandatory in HTTP requests, to resolve this issue, you can specify the "User-Agent" in the ‘webread’ request to mimic a web browser using ‘weboptions’.
Please follow the below code snippet to resolve the error:
url = 'https://finance.yahoo.com/quote/AAPL/options';
% Set the web options with a User-Agent to mimic a web browser
options = weboptions('UserAgent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3');
try
data = webread(url, options);
% Save retrieved page in HTML file
fid = fopen('AAPLOptions.html','w');
fprintf(fid, '%s\n',data);
fclose(fid);
catch err
disp(['Error: ', err.message]);
end
I was able to resolve the above error following the above steps.
The ‘User-Agent’ property of your browser can be found here
Please go through the following documentation pages to learn more about ‘webread’ and ‘weboptions’:
- https://www.mathworks.com/help/releases/R2020b/matlab/ref/weboptions.html
- https://www.mathworks.com/help/releases/R2020b/matlab/ref/webread.html
Hope this helps!
Thanks
Kanishk
0 comentarios
Ver también
Categorías
Más información sobre Web Services en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!