3
$\begingroup$

I have tabular data on a webpage. It looks like this:

Import["http://mfvonh.me/numericalTable.html", "Plaintext"]

1.0

1.1

3.53

However, I have many columns, so I want to import it using "Data":

Import[ "http://mfvonh.me/numericalTable.html" , "Data" ]

{ 1. , 1.1 , 3.53 }

I'd like to prevent Import from converting number-like forms to numbers, as it has done above, and simply extract all tabular data as strings. Obviously there are easy ways to hack this with a workaround; I am looking for an answer that involves Import[ _ , "Data" ].

I assume this conversion is somewhere in the Trace, but I was overwhelmed when I tried to look at it:

(Import["http://mfvonh.me/numericalTable.html", "Data"] // 
  Trace) >> "trace.txt"

produced 26 megabytes of plain text.

I took a look. Now I'm stuck.

$\endgroup$
1
  • $\begingroup$ I guess you can leave out the edit, as long as it duplicates your answer. $\endgroup$
    – Yves Klett
    Jun 4, 2014 at 15:22

2 Answers 2

3
$\begingroup$

You should use the "Numeric" -> False option:

Import["http://mfvonh.me/numericalTable.html", "Data", "Numeric" -> False]

{"1.0", "1.1", "3.53"}

This option is listed under Options on the Documentation page for HTML.

$\endgroup$
4
$\begingroup$
Block[
  {ToExpression},
  ToExpression[ x_String /; 
    StringMatchQ[ x, RegularExpression[ "\\d+(\\.\\d+)?" ] ] ] := x ;
  Import[ "http://mfvonh.me/numericalTable.html" , "Data" ] ]

{"1.0", "1.1", "3.53"}

$\endgroup$
1
  • $\begingroup$ +1 for resourcefulness, although in this case your solution is an overkill. :) $\endgroup$ Jun 4, 2014 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.