0
$\begingroup$

I want to import data from this website: http://hq.sinajs.cn/list=sh601006;

It should look like

var hq_str_sh601006= "大秦铁路,13.13,12.87,13.37,13.77,12.95,13.38,13.39,356310317,4776670723,1630,13.38,21200,13.37,62186,13.36,104760,13.35,152300,13.34,71700,13.39,55056,13.40,24100,13.41,39400,13.42,22366,13.43,2015-04-17,15:03:06,00";"

but when I input

Import["http://hq.sinajs.cn/list=sh601006"]

the output is $Failed. How can I fix this?

$\endgroup$

closed as off-topic by Oleksandr R., m_goldberg, bbgodfrey, Öskå, ciao Apr 19 '15 at 16:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Oleksandr R., m_goldberg, bbgodfrey, Öskå, ciao
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

It looks like Import has trouble with the character encoding on my computer:

Import["http://hq.sinajs.cn/list=sh601006", "HTML"]
(* "var hq_str_sh601006="`óÇØÌú·,13.13,12.87,13.37,13.77,12.95,13.38, [...] ;" *)

We can find the encoding by looking at the HTML headers:

Grid@URLFetch["http://hq.sinajs.cn/list=sh601006", "Headers"]
Cache-Control   no-cache
Content-Length  239
Connection      Keep-Alive
Content-Type    application/x-javascript; charset=GBK

"GBK" is not one of the possible $CharacterEncodings. We can try all possible encodings to see if any work:

Grid[Table[{e, 
   Import["http://hq.sinajs.cn/list=sh601006", "Text", 
    CharacterEncoding -> e]}, {e, $CharacterEncodings}]]

I find that "CP936" and "MacintoshChineseSimplified" work:

Import["http://hq.sinajs.cn/list=sh601006", "HTML", CharacterEncoding -> "CP936"]
(* var hq_str_sh601006="大秦铁路,13.13,12.87,13.37,13.77,12.95,13.38,13.39 [...] "; *)
$\endgroup$
1
$\begingroup$

I have found that

Import["http://hq.sinajs.cn/list=sh601006", "HTML"]

works.

$\endgroup$
  • $\begingroup$ I have found that "Text" works well on unformatted data. $\endgroup$ – 2012rcampion Apr 19 '15 at 15:24

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