Matlab will not read this webpage using webread(). What am I doing wrong?

31 visualizaciones (últimos 30 días)
Adam Wylie
Adam Wylie el 21 de Feb. de 2023
Editada: DGM el 21 de Feb. de 2023
clc
clear all
fn = 'Dataset.xlsx';
tBC = [];
opt = detectImportOptions(fn);
shts = sheetnames(fn);
for i=1:1
tBC=[tBC;readtable(fn,opt,'Sheet',shts(i))];
end
a = tBC.(9);
B = string(a)
check = B(1)
webread(check,options)
check =
"https://www.congress.gov/bill/102nd-congress/house-joint-resolution/13"
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray
The server returned the status 403 with message
"Forbidden" in response to the request to URL
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in CodeForEm (line 21)
webread(check,options)
  2 comentarios
Luca Ferro
Luca Ferro el 21 de Feb. de 2023
Editada: Luca Ferro el 21 de Feb. de 2023
in:
webread(check,options)
options has no set value or am i mistaken?
anyways i tried:
webread('https://www.congress.gov/bill/102nd-congress/house-joint-resolution/13')
and it works on my machine
Anton Kogios
Anton Kogios el 21 de Feb. de 2023
I think Adam may have tried options but omitted it from the post.
I get the same error as Adam when I try:
webread('https://www.congress.gov/bill/102nd-congress/house-joint-resolution/13')
which is pretty interesting I guess?
Maybe it is to do with location? I am outside of the US.

Iniciar sesión para comentar.

Respuestas (1)

Anton Kogios
Anton Kogios el 21 de Feb. de 2023
This page is likely protected against automated access (see https://mathworks.com/matlabcentral/answers/365957-why-do-i-get-this-error-message-forbidden-when-trying-to-read-web-data). You may be able to play around with weboptions (particularly username and password if you have an account), but I predict that it will still not work. I do not think there is anything wrong with your code, as this code works with other websites. Here is a list of HTTP Status Codes.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by