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

25 ビュー (過去 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 Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by