urlread retrieves data but webread retrieves error

7 views (last 30 days)
I'd like to retrieve data from a .csv generated by a website. urlread works, but is not recommended. webread returns a http error message. Anyone know what feature of webread causes different behavior than urlread? Alternatively, is there a script to just download the file (e.g. web.m but without the interactive browser)?
>> urlread('https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1')
ans =
'spkid,full_name
1000099," 8P/Tuttle"
1000061," 96P/Machholz 1"
1000047," 126P/IRAS"
1000154," 262P/McNaught-Russell"
1003435," 333P/LINEAR"
1002585," 342P/SOHO"
1001439," P/1999 J6 (SOHO)"
1001843," C/2002 R5 (SOHO)"
1001852," P/2002 S7 (SOHO)"
1002413," P/2006 R1 (Siding Spring)"
1003317," P/2008 Y12 (SOHO)"
1003064," P/2010 D2 (WISE)"
1003231," P/2013 AL76 (Catalina)"
1003377," C/2015 D1 (SOHO)"
'
>> webread('https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1')
ans =
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>ERROR</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body bgcolor="#FFFFFF" link="#FF0000" vlink="#0000FF">
<h2>Error Condition</h2>
</body>
</html>

Accepted Answer

Damon Landau
Damon Landau on 25 May 2018
webread apparently doesn't like the semicolon delimiter between fields. I changed the semicolons to ampersands and it works.
  2 Comments
Mark Magdaleno
Mark Magdaleno on 13 May 2021
I have the same issue.
How is this an "Accepted Answer"? If I understand the fix is to manully edit the file to change the delimiters by hand?
Can webread delimiter be user settable? If not will urlread stay put until it does?
Walter Roberson
Walter Roberson on 13 May 2021
url = 'https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1'
url = 'https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1'
url_amp = regexprep(url, ';', '&')
url_amp = 'https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC&table_format=CSV&c_fields=AbAc&&query=1'
char(webread(url_amp).')
ans =
'spkid,full_name 1000099," 8P/Tuttle" 1000061," 96P/Machholz 1" 1000047," 126P/IRAS" 1000154," 262P/McNaught-Russell" 1003435," 333P/LINEAR" 1001542," 342P/SOHO" 1002413," 389P/Siding Spring" 1000981," C/1914 S1 (Campbell)" 1001439," P/1999 J6 (SOHO)" 1001843," C/2002 R5 (SOHO)" 1001852," P/2002 S7 (SOHO)" 1003317," P/2008 Y12 (SOHO)" 1003064," P/2010 D2 (WISE)" 1003231," P/2013 AL76 (Catalina)" 1003377," C/2015 D1 (SOHO)" 1003593," P/2017 TW13 (Lemmon)" '

Sign in to comment.

More Answers (0)

Categories

Find more on Downloads in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!