An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111224/a77aa218/attachment.pl>
readLines errors
5 messages · zhijie zhang, David Winsemius
On Dec 24, 2011, at 4:12 AM, rusers.sh wrote:
Hi All,
I met a problem using readLines function to return the data from
Google
maps.
readLines(url("
http://ditu.google.cn/maps/geo?q=+qianshuichong,+guichi+anhui,+CN&output=csv&key=ABQIAAAAq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
"),
n=1, warn=FALSE)
[1] "200,4,30.6528380,117.4872250"
The above code is ok because the address is English, but it cannot
work
when i change the address into zh-hans (Chinese simplified). See
below.
readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5
%86%B2>
,+????+????,
+
??
?
?
&output
=
csv
&key
=
ABQIAAAAq8Fnd_oUka
-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
&language=zh-CN®ion=zh_Hans"),
n=1, warn=FALSE)
When I plug that URL into my browser (Firefox) I get this text on a
white background:
602,0,0,0
When I execute that code in R I get:
[1] "{"
And when I remove the lines restriction I get:
[1] "{"
[2] " \"name\": \" ??????\\u003chttp://ditu.google.cn/maps/geo?
q= ???\\u003e\","
[3] " \"Status\": {"
[4] " \"code\": 602,"
[5] " \"request\": \"geocode\""
[6] " }"
[7] "}"
I don't read Chinese , however it does appear that there was some sort
of extra processing step that Firefox carried out to arrive at the
displayed text.
[1] "400,0,0,0"
The returned value is wrong. I also tried several other options, but
still have the same problem. The interesting thing is if i paste the
URL
into the IE explorer directly, it do return the correct values.
Anybody can give me some suggestions or hints to solve this?
Thanks a lot.
P.S. See below for the other possibilities i tried.
readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5
%86%B2>
,+????+????,
+
??
?
?
&output
=
csv
&key
=
ABQIAAAAq8Fnd_oUka
-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
&language=zh-CN®ion=zh"),
n=1, warn=FALSE)
[1] "400,0,0,0"
readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5
%86%B2>
,+????+????,
+
??
?
?
&output
=
csv
&key
=
ABQIAAAAq8Fnd_oUka
-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
&language=zh-CN"),
n=1, warn=FALSE)
[1] "400,0,0,0"
readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5
%86%B2>
,+????+????,
+
??
?
?
&output
=
csv
&key
=
ABQIAAAAq8Fnd_oUka
-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
&language=zh-CN"),
n=1, warn=FALSE,encoding="UTF-8")
[1] "400,0,0,0"
--
-----------------
Jane Chang
Queen's
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111224/83e0e39a/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111224/df0961f2/attachment.pl>
On Dec 24, 2011, at 9:55 AM, rusers.sh wrote:
Hi All, I just tried Firefox that David referred and found it can also return the correct result as Google Chrome. So now it is more clear now that readLines() function uses IE as the default explorer, so it return the wrong result. Then the possible solutions are, 1. Could we change the options in readLines() to set another explorer as the default explore, e.g. Google Chrome?
?options # and look at the HTTPUserAgent choice I believe this: > options()$HTTPUserAgent [1] "R (2.14.0 x86_64-apple-darwin9.8.0 x86_64 darwin9.8.0)" ... is telling me that the choice is passed off to the OS, and only because you keep referring to (MS)IE do we know that you are running one of that Redmond company's products. (You should evidently do more study of the relationship of R to the OS platform you use.)
2. Could it be possible to set IE explorer in a rational way, so that it can return the same results as Google Chrome and Firefox? I have tried to modify the encoding method in IE, but it doesnot work. Any suggestions or help?
That is not an appropriate question for this mailing list. You persist in posting in HTML. Maybe you should also spend more time learning to use you mail client correctly?
David.
>
> ?? 2011??12??24?? ????5:12??rusers.sh <rusers.sh at gmail.com>??????
>
>> Hi All,
>> I met a problem using readLines function to return the data from
>> Google
>> maps.
>>
>> readLines(url("
>> http://ditu.google.cn/maps/geo?q=+qianshuichong,+guichi+anhui,+CN&output=csv&key=ABQIAAAAq8Fnd_oUka-7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
>> "),
>> n=1, warn=FALSE)
>>
>> [1] "200,4,30.6528380,117.4872250"
>>
>> The above code is ok because the address is English, but it cannot
>> work
>> when i change the address into zh-hans (Chinese simplified). See
>> below.
>>
>> readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2
>> >
>> ,+????+????,
>> +
>> ??
>> ?
>> ?
>> &output
>> =
>> csv
>> &key
>> =
>> ABQIAAAAq8Fnd_oUka
>> -7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
>> &language=zh-CN®ion=zh_Hans"),
>> n=1, warn=FALSE)
>>
>> [1] "400,0,0,0"
>>
>> The returned value is wrong. I also tried several other options, but
>> still have the same problem. The interesting thing is if i paste
>> the URL
>> into the IE explorer directly, it do return the correct values.
>>
>> Anybody can give me some suggestions or hints to solve this?
>>
>> Thanks a lot.
>>
>> P.S. See below for the other possibilities i tried.
>>
>> readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2
>> >
>> ,+????+????,
>> +
>> ??
>> ?
>> ?
>> &output
>> =
>> csv
>> &key
>> =
>> ABQIAAAAq8Fnd_oUka
>> -7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
>> &language=zh-CN®ion=zh"),
>> n=1, warn=FALSE)
>>
>> [1] "400,0,0,0"
>>
>> readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2
>> >
>> ,+????+????,
>> +
>> ??
>> ?
>> ?
>> &output
>> =
>> csv
>> &key
>> =
>> ABQIAAAAq8Fnd_oUka
>> -7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
>> &language=zh-CN"),
>> n=1, warn=FALSE)
>>
>> [1] "400,0,0,0"
>>
>> readLines(url("http://ditu.google.cn/maps/geo?q=+??????<http://ditu.google.cn/maps/geo?q=+%E5%89%8D%E6%B0%B4%E5%86%B2
>> >
>> ,+????+????,
>> +
>> ??
>> ?
>> ?
>> &output
>> =
>> csv
>> &key
>> =
>> ABQIAAAAq8Fnd_oUka
>> -7RdS6BrD7GBTqeABoQuNTXS36G_rkiwQnKRW6GBTkns8JpKz6y6dScgB8827dlddUlg
>> &language=zh-CN"),
>> n=1, warn=FALSE,encoding="UTF-8")
>>
>> [1] "400,0,0,0"
>>
>>
>> --
David Winsemius, MD
West Hartford, CT