필터 지우기
필터 지우기

How to read a table from an url?

조회 수: 22 (최근 30일)
tom3w
tom3w 2016년 12월 2일
답변: Toshiaki Takeuchi 2023년 10월 24일
Hi, I'd need some help. How is it possible to read a table from an url?
The following sequence allows constructing a URL object, opening a URL connection, setting up a buffered stream reader, and reading lines (line by line):
url = java.net.URL('http://www.mathworks.com')
is = openStream(url);
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);
s = char(readLine(br)); % can be repeated
I think bufferedReader is only appropriate to read contents row by row. In case the webpage contains a table, this code works, but does not read all the elements of the table, i.e. tbody
Example (java contents)
<div class="table-responsive no-padding-top"> : start of table, displayed in Matlab (e.g. command window)
<table width=... > : table formatting, displayed in Matlab
<thead>: start of table header, displayed in Matlab
<tr>: entire row related to table header, displayed in Matlab
<th> ... </th>: 1st element of header, displayed in Matlab
<th> ... </th>: 2nd element of header, displayed in Matlab
...
</tr>, displayed in Matlab
</thead>: end of header/description of column names, displayed in Matlab
<tbody>: full table with its contents, "<tbody>" displayed in Matlab
<tr>: 1st row of table, *not displayed* in Matlab
<td>...</td>: 1st cell of 1st row, *not displayed* in Matlab
<td>...</td>: 2nd cell of 1st row, *not displayed* in Matlab
</tr>: end of 1st row, *not displayed* in Matlab
<tr>: 2nd row of table, *not displayed* in Matlab
<td>...</td>: 1st cell of 1st row, *not displayed* in Matlab
<td>...</td>: 2nd cell of 1st row, *not displayed* in Matlab
</tr>: end of 2nd row, *not displayed* in Matlab
</tbody>: end of table contents, "</tbody>" displayed in Matlab
</table>: end of table object, displayed in Matlab
How can we read the details behind a table body (tbody)?
Many thanks for your support!
Thomas

채택된 답변

Sid Jhaveri
Sid Jhaveri 2016년 12월 6일
편집: KSSV 2023년 6월 22일
  댓글 수: 1
tom3w
tom3w 2016년 12월 7일
The webread function works pretty well. Thank you Sid for your suggestions. Kr, Thomas

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

추가 답변 (1개)

Toshiaki Takeuchi
Toshiaki Takeuchi 2023년 10월 24일
url = "https://www.mathworks.com/help/matlab/text-files.html";
T = readtable(url,TableSelector="//TABLE[contains(.,'readtable')]", ...
ReadVariableNames=false)
T = 4×2 table
Var1 Var2 ________________ ___________________________________________ "readtable" "Create table from file" "writetable" "Write table to file" "readtimetable" "Create timetable from file (Since R2019a)" "writetimetable" "Write timetable to file (Since R2019a)"

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by