"webread" does not work for Yahoo Option Chains page

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?

댓글 수: 4

Note that
webread('https://finance.yahoo.com/quote/AAPL/')
works.
Cengiz Esmersoy
Cengiz Esmersoy 2024년 8월 5일
편집: Cengiz Esmersoy 2024년 8월 5일
Yes, it works for stocks, but not for options. This makes me think there may be an access block by Yahoo, but this would typically be status 401.
And, I understand from blog traffic Pyton can access it, although I have not tried myself.
Access blocks would typically be error 403, Access Prohibitted.
Adriano
Adriano 2024년 10월 31일
이동: Walter Roberson 2024년 10월 31일
I get this error message:
Error: The server returned the status 404 with message "Not Found" in response to the request to URL https://finance.yahoo.com/quote/AAPL/options/.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kanishk
Kanishk 2024년 8월 13일
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:
Hope this helps!
Thanks
Kanishk

제품

릴리스

R2020b

태그

질문:

2024년 8월 4일

이동:

2024년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by