我通过google api服务计算了城市之间的距离。我需要将距离转换为 R 中的距离矩阵,但是当我使用代码时:
de1 <- "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&destinations=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&mode=driving&language=en&sensor=false"
webpage1 <- getURL(de1)
webpage1 <- readLines(tc <- textConnection(webpage1)); close(tc)
pagetree <- htmlTreeParse(webpage1, error=function(...){})
如果我然后键入“pagetree”,我会收到一条错误消息。
> pagetree
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href="//www.google.com/"><img src="//www.google.com/images/errors/logo_sm.gif" alt="Google"></a>
</head>
<body>
<p><b>400.</b> <ins>That’s an error.</ins>
</p>
<p>Your client has issued a malformed or illegal request. <ins>That’s all we know.</ins></p>
</body>
</html>
有人可以帮帮我吗?
谢谢你,索菲亚页。