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

31 次查看(过去 30 天)
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 个评论
Luca Ferro
Luca Ferro 2023-2-21
编辑:Luca Ferro 2023-2-21
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 2023-2-21
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.

请先登录,再进行评论。

回答(1 个)

Anton Kogios
Anton Kogios 2023-2-21
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.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by