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

31 Ansichten (letzte 30 Tage)
Adam Wylie
Adam Wylie am 21 Feb. 2023
Bearbeitet: DGM am 21 Feb. 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 Kommentare
Luca Ferro
Luca Ferro am 21 Feb. 2023
Bearbeitet: Luca Ferro am 21 Feb. 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 am 21 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Anton Kogios
Anton Kogios am 21 Feb. 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.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by