2013-04-20 2 views
2

CORINE Land Cover zip 파일을 this site에서 대량 다운로드하려고합니다. Google Analytics의 상호 연결된 피드백 설문 조사 창에서 문제가 발생하고 있습니다. 여기에는 몇 가지 종류의 컬 처리기가 있습니까? 이 문제들에 대해서?여러 개의 URL에서 자동으로 다운로드하여 피드백 대화 상자/쿠키 처리

sqlite 관리자에서 쿠키를 보았습니다. baseDomain = "europa.eu", name = "clc06_c133.zip", value = "sectors % 3Denvironment", host = "www.eea.europa. 유럽 ​​연합 (EU) C ".. 쿠키 경로가": \ 사용자 \ 케이 \의 AppData \ 로밍 \ 모질라 \ 파이어 폭스 \ 프로필 \ ckut8fjm.default \ cookies.sqlite "

setwd("D:/GIS DataBase/CorineLC/") 

mylist <- list(
clc06_1 <- "111 - Continuous urban fabric", 
clc06_2 <- "112 - Discontinuous urban fabric", 
clc06_3 <- "121 - Industrial or commercial units", 
clc06_4 <- "122 - Road and rail networks and associated land", 
clc06_5 <- "123 - Port areas", 
clc06_6 <- "124 - Airports", 
clc06_7 <- "131 - Mineral extraction sites", 
clc06_8 <- "132 - Dump sites", 
clc06_9 <- "133 - Construction sites", 
clc06_10 <- "141 - Green urban areas", 
clc06_11 <- "142 - Sport and leisure facilities", 
clc06_12 <- "211 - Non-irrigated arable land", 
clc06_13 <- "212 - Permanently irrigated land", 
clc06_14 <- "213 - Rice fields", 
clc06_15 <- "221 - Vineyards", 
clc06_16 <- "222 - Fruit trees and berry plantations", 
clc06_17 <- "223 - Olive groves", 
clc06_18 <- "231 - Pastures", 
clc06_19 <- "241 - Annual crops associated with permanent crops", 
clc06_20 <- "242 - Complex cultivation patterns", 
clc06_21 <- "243 - Land principally occupied by agriculture, with significant areas of natural vegetation", 
clc06_22 <- "244 - Agro-forestry areas", 
clc06_23 <- "311 - Broad-leaved forest", 
clc06_24 <- "312 - Coniferous forest", 
clc06_25 <- "313 - Mixed forest", 
clc06_26 <- "321 - Natural grasslands", 
clc06_27 <- "322 - Moors and heathland", 
clc06_28 <- "323 - Sclerophyllous vegetation", 
clc06_29 <- "324 - Transitional woodland-shrub", 
clc06_30 <- "331 - Beaches, dunes, sands", 
clc06_31 <- "332 - Bare rocks", 
clc06_32 <- "333 - Sparsely vegetated areas", 
clc06_33 <- "334 - Burnt areas", 
clc06_34 <- "335 - Glaciers and perpetual snow", 
clc06_35 <- "411 - Inland marshes", 
clc06_36 <- "412 - Peat bogs", 
clc06_37 <- "421 - Salt marshes", 
clc06_38 <- "422 - Salines", 
clc06_39 <- "423 - Intertidal flats", 
clc06_40 <- "511 - Water courses", 
clc06_41 <- "512 - Water bodies", 
clc06_42 <- "521 - Coastal lagoons", 
clc06_43 <- "522 - Estuaries", 
clc06_44 <- "523 - Sea and ocean") 

# extract the CLC codes which are the 3-digit number in the string: 
foo1 <- function(x) unlist(strsplit(x, " - "))[[1]] 
# and the names 
foo2 <- function(x) unlist(strsplit(x, " - "))[[2]] 

codes <- sapply(mylist, foo1, simplify = T) 
names <- sapply(mylist, foo2, simplify = T) 

# make urls 
names_url <- gsub(",", "", gsub("\\s", "-", names)) 
dl_url <- paste0("http://www.eea.europa.eu/data-and-maps/data/clc-2006-vector-data-version-2/", 
       codes, "-", names_url, "/clc06_c", codes, ".zip/at_download/file") 

# get zip file names 
get_zip_name <- function(x) unlist(strsplit(x, "/"))[grep(".zip", unlist(strsplit(x, "/")))] 

# function to plug into sapply 
dl_url_to_zip <- function(x) download.file(x, dest = get_zip_name(x)) 

# gives http status 404! 
sapply(dl_url, dl_url_to_zip) 

답변

3

당신은 httr 패키지를 사용할 수 있습니다 :

require(httr) 
require(XML) 

response <- GET("http://www.eea.europa.eu/data-and-maps/data/clc-2006-vector-data-version-2") 
doc <- htmlParse(content(response,as="text")) 
files <- xpathSApply(doc,'//*/a[contains(@href,"http://www.eea.europa.eu/data-and-maps/data/clc-2006-vector-data-version-2/")]/@href') 
files <- files[-c(1,47:50)] 

files[10] 
#href 
#"http://www.eea.europa.eu/data-and-maps/data/clc-2006-vector-data-version-2/141-green-urban-areas/clc06_c141.zip/at_download/file" 
dl_url[10] 
#[1] "http://www.eea.europa.eu/data-and-maps/data/clc-2006-vector-data-version-2/141-Green-urban-areas/clc06_c141.zip/at_download/file" 

대신에 대문자가 있었던 것 같습니다. 나는 우리가 쿠키를해야 할 수도 있습니다 가정으로

response <- GET(files[10]) 
writeBin(content(response),'test.zip') 

나는 httr 패키지와 함께 시작했다. 사실

download.file(files[10],'test.zip',mode="wb") 

도 똑같이 작동합니다. 원래 코드의 오류는 대소 문자입니다.

+0

'htmlParse()'는'htmlParse :: XML'을 의미합니까? 패키지를로드하고 함수를 사용하면 오류 메시지가 나타납니다 :'htmlParse의 오류 (내용 (response, as = "text")) : File'. 수동으로 다운로드 할 때이 체크 의견 설문지에는 체크 표시가 2 개 필요합니다 (해당 입력은 내가 믿는 쿠키에 저장됩니다) - 귀하의 접근 방식에 대한 설명이 있습니까? – Kay

+0

젠장, 내 코드가 실제로 작동했다 - 대문자 이름이었다 !! 그러나, XML을 사용하면 훨씬 더 우아하고 작동하도록하고 싶습니다! 다음이 모든 파일에 대해 작동합니까 (여러 항목이 4 개의 별도 사이트에 표시됩니까)? – Kay

+0

XML 패키지가 필요합니다. 추가했습니다. 나는 틀린 httr가 그것에 의지했다고 추정했다. – user1609452

관련 문제