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

조회 수: 31 (최근 30일)
Adam Wylie
Adam Wylie 2023년 2월 21일
편집: DGM 2023년 2월 21일
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.
  댓글 수: 1
DGM
DGM 2023년 2월 21일
편집: DGM 2023년 2월 21일
This seems likely, since they offer an API for automated access:

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

카테고리

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