我对 R 编码非常陌生,所以希望得到一些帮助!尝试通过明尼苏达州DNR网站进行一些湖泊人口管理分析。我已经尝试过ReadHTLMLtable和HTMLparse,但是如果我正在寻找一个特定的表,它似乎只能工作。如果我在许多不同的页面(即不同的湖泊)上寻找相同的表格,那么它就会搞砸了。
以下是我要做的事情:
在 R 中构建代码,从明尼苏达州DNR中抓取1个表格,用于各种各样的湖泊 (参见链接示例:http://www.dnr.state.mn.us/lakefind/showreport.html?downum=56011602)
我感兴趣的表名为“选择种类的长度 - 所有齿轮组合”
在多个不同的湖泊上执行此数据抓取并将数据导出到Excel
任何指针都会很棒!如果可能的话,自动化它来完成一个县内的所有湖泊将是理想的,但这是一个开始!
答案 0 :(得分:1)
啊,即使您已经尝试过标准的rvest
调用,也不会感谢它为获取表数据而进行的javascript调用。
使用RSelenium,splashr
或以下(网页调用相同的API):
library(httr)
res <- GET("http://maps2.dnr.state.mn.us/cgi-bin/lakefinder/detail.cgi",
query=list(type="lake_survey",
id="56011602",
`_`=as.numeric(Sys.time())*1000))
str(content(res, as="parsed", simplifyVector=TRUE))
## List of 4
## $ timestamp: int 1488159503
## $ status : chr "SUCCESS"
## $ result :List of 13
## ..$ averageWaterClarity: chr "5.0"
## ..$ sampledPlants : list()
## ..$ officeCode : chr "F115"
## ..$ littoralAcres : int 113
## ..$ shoreLengthMiles : num 4.26
## ..$ areaAcres : num 423
## ..$ surveys :'data.frame': 6 obs. of 8 variables:
## .. ..$ fishCatchSummaries:List of 6
## .. .. ..$ :'data.frame': 22 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:22] "0.4-1.3" "2.5-16.5" "0.3-1.2" "1.2-6.3" ...
## .. .. .. ..$ CPUE : chr [1:22] "0.80" "0.75" "0.20" "1.00" ...
## .. .. .. ..$ totalCatch : int [1:22] 4 3 1 4 20 32 12 86 4 1 ...
## .. .. .. ..$ species : chr [1:22] "BOF" "BLC" "WAE" "WAE" ...
## .. .. .. ..$ totalWeight : num [1:22] 25.4 1.4 1.3 3.4 49 29 11.1 5.4 2.1 0.1 ...
## .. .. .. ..$ quartileWeight: chr [1:22] "2.3-4.1" "0.1-0.3" "0.8-2.8" "1.2-2.7" ...
## .. .. .. ..$ averageWeight : chr [1:22] "6.35" "0.47" "1.30" "0.85" ...
## .. .. .. ..$ gearCount : int [1:22] 5 4 5 4 4 5 4 5 5 4 ...
## .. .. .. ..$ gear : chr [1:22] "Standard trap nets" "Standard gill nets" "Standard trap nets" "Standard gill nets" ...
## .. .. ..$ :'data.frame': 23 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:23] "2.5-16.5" "N/A" "0.3-1.2" "0.2-0.8" ...
## .. .. .. ..$ CPUE : chr [1:23] "0.20" "0.43" "0.57" "0.20" ...
## .. .. .. ..$ totalCatch : int [1:23] 1 3 4 1 16 52 27 16 20 5 ...
## .. .. .. ..$ species : chr [1:23] "BLC" "NOP" "WAE" "BOF" ...
## .. .. .. ..$ totalWeight : num [1:23] 0.1 10.6 6.5 8 22.9 82.6 27 14.2 2.9 4.9 ...
## .. .. .. ..$ quartileWeight: chr [1:23] "0.1-0.3" "N/A" "0.8-2.8" "2.4-4.2" ...
## .. .. .. ..$ averageWeight : chr [1:23] "0.10" "3.53" "1.62" "8.00" ...
## .. .. .. ..$ gearCount : int [1:23] 5 7 7 5 5 5 7 5 7 7 ...
## .. .. .. ..$ gear : chr [1:23] "Standard gill nets" "Standard trap nets" "Standard trap nets" "Standard gill nets" ...
## .. .. ..$ :'data.frame': 24 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:24] "2.5-16.5" "N/A" "0.3-1.2" "0.9-5.7" ...
## .. .. .. ..$ CPUE : chr [1:24] "0.40" "0.67" "0.17" "16.67" ...
## .. .. .. ..$ totalCatch : int [1:24] 2 4 1 100 17 8 27 11 200 5 ...
## .. .. .. ..$ species : chr [1:24] "BLC" "NOP" "WAE" "YEB" ...
## .. .. .. ..$ totalWeight : num [1:24] 2.25 9.5 2 68 26.91 ...
## .. .. .. ..$ quartileWeight: chr [1:24] "0.1-0.3" "N/A" "0.8-2.8" "0.5-0.8" ...
## .. .. .. ..$ averageWeight : chr [1:24] "1.12" "2.38" "2.00" "0.68" ...
## .. .. .. ..$ gearCount : int [1:24] 5 6 6 6 5 5 5 6 6 5 ...
## .. .. .. ..$ gear : chr [1:24] "Standard gill nets" "Standard trap nets" "Standard trap nets" "Standard trap nets" ...
## .. .. ..$ :'data.frame': 28 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:28] "0.4-1.3" "2.5-16.5" "0.3-1.2" "0.2-0.8" ...
## .. .. .. ..$ CPUE : chr [1:28] "0.33" "0.56" "0.56" "0.44" ...
## .. .. .. ..$ totalCatch : int [1:28] 3 5 5 4 6 69 27 12 10 62 ...
## .. .. .. ..$ species : chr [1:28] "BOF" "BLC" "WAE" "BOF" ...
## .. .. .. ..$ totalWeight : int [1:28] 5380 1356 2320 11350 3446 48119 19484 4984 3084 3150 ...
## .. .. .. ..$ quartileWeight: chr [1:28] "2.3-4.1" "0.1-0.3" "0.8-2.8" "2.4-4.2" ...
## .. .. .. ..$ averageWeight : chr [1:28] "3.95" "0.60" "1.02" "6.26" ...
## .. .. .. ..$ gearCount : int [1:28] 9 9 9 9 9 9 9 9 9 9 ...
## .. .. .. ..$ gear : chr [1:28] "Standard trap nets" "Standard gill nets" "Standard trap nets" "Standard gill nets" ...
## .. .. ..$ :'data.frame': 28 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:28] "0.4-1.3" "2.5-16.5" "0.3-1.2" "0.2-0.8" ...
## .. .. .. ..$ CPUE : chr [1:28] "0.11" "3.44" "0.22" "0.22" ...
## .. .. .. ..$ totalCatch : int [1:28] 1 31 2 2 4 35 8 6 23 9 ...
## .. .. .. ..$ species : chr [1:28] "BOF" "BLC" "WAE" "BOF" ...
## .. .. .. ..$ totalWeight : int [1:28] 1280 6859 1310 2300 1807 26553 6205 2279 10343 875 ...
## .. .. .. ..$ quartileWeight: chr [1:28] "2.3-4.1" "0.1-0.3" "0.8-2.8" "2.4-4.2" ...
## .. .. .. ..$ averageWeight : chr [1:28] "2.82" "0.49" "1.44" "2.54" ...
## .. .. .. ..$ gearCount : int [1:28] 9 9 9 9 9 9 9 9 9 9 ...
## .. .. .. ..$ gear : chr [1:28] "Standard trap nets" "Standard gill nets" "Standard trap nets" "Standard gill nets" ...
## .. .. ..$ :'data.frame': 25 obs. of 9 variables:
## .. .. .. ..$ quartileCount : chr [1:25] "2.5-16.5" "0.3-1.2" "0.2-0.8" "N/A" ...
## .. .. .. ..$ CPUE : chr [1:25] "3.00" "0.22" "0.11" "0.11" ...
## .. .. .. ..$ totalCatch : int [1:25] 27 2 1 1 11 1 85 7 3 1 ...
## .. .. .. ..$ species : chr [1:25] "BLC" "WAE" "BOF" "NOP" ...
## .. .. .. ..$ totalWeight : int [1:25] 4743 3009 2200 934 13597 2350 58380 3128 1612 100 ...
## .. .. .. ..$ quartileWeight: chr [1:25] "0.1-0.3" "0.8-2.8" "2.4-4.2" "N/A" ...
## .. .. .. ..$ averageWeight : chr [1:25] "0.39" "3.32" "4.85" "2.06" ...
## .. .. .. ..$ gearCount : int [1:25] 9 9 9 9 9 9 9 9 9 9 ...
## .. .. .. ..$ gear : chr [1:25] "Standard gill nets" "Standard trap nets" "Standard gill nets" "Standard trap nets" ...
## .. ..$ surveyDate : chr [1:6] "1989-08-02" "1984-08-01" "1978-08-07" "1999-08-02" ...
## .. ..$ surveySubType : chr [1:6] "Population Assessment" "Population Assessment" "Re-Survey" "Population Assessment" ...
## .. ..$ headerInfo :List of 6
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "1989-08-02" ...
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "1984-08-01" ...
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "1978-08-07" ...
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "1999-08-02" ...
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "2004-08-02" ...
## .. .. ..$ : chr [1:6] "East Leaf" NA "56011602" "2010-08-02" ...
## .. ..$ surveyType : chr [1:6] "Standard Survey" "Standard Survey" "Standard Survey" "Standard Survey" ...
## .. ..$ narrative : chr [1:6] "<p>NOP ABUNDANCE HAS DECLINED FROM 10.4 PER GILL NET LIFT IN 1984 TO 5.0 DURING THIS SURVEY. AVERAGE WEIGHT OF NOP WAS 2.5 POU"| __truncated__ "<p>NETTING DATA INDICATES THAT NORTHERN PIKE AND YELLOW PERCH NUMBERS ARE ABOVE THE AREA NET MEDIAN BLUEGILL, PUMPKINSEED, LARG"| __truncated__ "<p>TEST NET CATCHES OF YEP, BLBS AND YEBS WERE ABOVE AVERAGE. WAES AND SUCKERS WERE CAUGHT IN NEAR AVERAGE NUMBERS AND TULLIBE"| __truncated__ "<p>East Leaf Lake is a 404 acre mesotrophic (moderately fertile) lake located in eastern Otter Tail County, approximately five "| __truncated__ ...
## .. ..$ surveyID : chr [1:6] "102083" "102084" "102085" "102592" ...
## .. ..$ lengths :'data.frame': 6 obs. of 18 variables:
## .. .. ..$ LMB:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 2 4 14
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:4, 1:2] 11 2 5 6 1 1 2 3
## .. .. .. .. ..$ : int [1:11, 1:2] 10 11 12 13 15 4 5 6 7 8 ...
## .. .. .. .. ..$ : int [1:2, 1:2] 14 15 1 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 11 15 15
## .. .. ..$ YEP:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 3 4 4
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:5, 1:2] 3 5 6 7 8 2 109 153 50 4
## .. .. .. .. ..$ : int [1:4, 1:2] 4 5 6 7 1 83 55 5
## .. .. .. .. ..$ : int [1:4, 1:2] 4 5 6 7 2 180 67 4
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 8 7 7
## .. .. ..$ BLG:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 3 3 3
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:7, 1:2] 3 4 5 6 7 8 9 27 27 33 ...
## .. .. .. .. ..$ : int [1:7, 1:2] 3 4 5 6 7 8 9 17 9 24 ...
## .. .. .. .. ..$ : int [1:7, 1:2] 3 4 5 6 7 8 9 6 1 5 ...
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 9 9 9
## .. .. ..$ NOP:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 11 11 13
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:14, 1:2] 11 13 14 15 16 17 18 19 20 21 ...
## .. .. .. .. ..$ : int [1:10, 1:2] 11 16 17 18 19 20 21 22 23 30 ...
## .. .. .. .. ..$ : int [1:12, 1:2] 13 14 15 16 17 18 19 20 21 22 ...
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 25 30 24
## .. .. ..$ WAE:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 9 7 13
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:12, 1:2] 11 12 13 14 15 16 17 18 19 20 ...
## .. .. .. .. ..$ : int [1:9, 1:2] 11 15 16 17 19 20 21 7 9 1 ...
## .. .. .. .. ..$ : int [1:10, 1:2] 13 14 15 16 17 19 20 24 25 26 ...
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 24 21 26
## .. .. ..$ TLC:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 11 NA 8
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:5, 1:2] 11 12 15 17 18 1 1 1 2 1
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1, 1:2] 8 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 18 NA 8
## .. .. ..$ BLB:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 6 12 6
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:3, 1:2] 10 6 9 2 1 1
## .. .. .. .. ..$ : int [1, 1:2] 12 1
## .. .. .. .. ..$ : int [1:3, 1:2] 13 15 6 1 1 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 10 12 15
## .. .. ..$ PMK:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 3 3 6
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:4, 1:2] 3 4 5 6 15 20 16 19
## .. .. .. .. ..$ : int [1:4, 1:2] 3 5 6 7 1 2 6 1
## .. .. .. .. ..$ : int [1, 1:2] 6 2
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 6 7 6
## .. .. ..$ RKB:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 3 5 5
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:6, 1:2] 3 4 5 6 7 8 1 3 2 1 ...
## .. .. .. .. ..$ : int [1:3, 1:2] 5 6 7 1 1 1
## .. .. .. .. ..$ : int [1:2, 1:2] 5 9 1 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 8 7 9
## .. .. ..$ YEB:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 6 8 11
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:6, 1:2] 10 11 12 13 6 9 9 4 2 4 ...
## .. .. .. .. ..$ : int [1:6, 1:2] 10 11 12 13 14 8 3 12 9 3 ...
## .. .. .. .. ..$ : int [1:3, 1:2] 11 12 13 4 5 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 13 14 13
## .. .. ..$ WTS:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 8 10 8
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:12, 1:2] 12 13 14 15 16 17 18 19 20 22 ...
## .. .. .. .. ..$ : int [1:10, 1:2] 10 12 13 14 15 16 17 18 19 20 ...
## .. .. .. .. ..$ : int [1:8, 1:2] 12 13 16 17 18 19 20 8 2 1 ...
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 22 20 20
## .. .. ..$ BOF:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 14 19 24
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:6, 1:2] 14 20 23 25 26 27 1 1 1 1 ...
## .. .. .. .. ..$ : int [1:3, 1:2] 19 20 21 1 1 1
## .. .. .. .. ..$ : int [1, 1:2] 24 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 27 21 24
## .. .. ..$ BRB:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 8 10 13
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:4, 1:2] 10 11 14 8 3 1 1 1
## .. .. .. .. ..$ : int [1:4, 1:2] 10 11 12 13 3 9 2 3
## .. .. .. .. ..$ : int [1:2, 1:2] 13 14 4 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 14 13 14
## .. .. ..$ CAP:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 14 23 NA
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1, 1:2] 14 1
## .. .. .. .. ..$ : int [1, 1:2] 23 1
## .. .. .. .. ..$ : NULL
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 14 23 NA
## .. .. ..$ SHR:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 10 11 NA
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1, 1:2] 10 1
## .. .. .. .. ..$ : int [1:3, 1:2] 11 14 16 2 2 2
## .. .. .. .. ..$ : NULL
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 10 16 NA
## .. .. ..$ BLC:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA 4 5 4
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1:4, 1:2] 10 4 8 9 2 1 1 10
## .. .. .. .. ..$ : int [1:7, 1:2] 10 11 12 5 6 8 9 7 4 1 ...
## .. .. .. .. ..$ : int [1:9, 1:2] 10 11 12 4 5 6 7 8 9 90 ...
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA 10 12 12
## .. .. ..$ HSF:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA NA NA 6
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1, 1:2] 6 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA NA NA 6
## .. .. ..$ GRR:'data.frame': 6 obs. of 3 variables:
## .. .. .. ..$ minimum_length: int [1:6] NA NA NA NA NA 22
## .. .. .. ..$ fishCount :List of 6
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : NULL
## .. .. .. .. ..$ : int [1, 1:2] 22 1
## .. .. .. ..$ maximum_length: int [1:6] NA NA NA NA NA 22
## ..$ accesses :'data.frame': 1 obs. of 5 variables:
## .. ..$ accessTypeId : chr "CO"
## .. ..$ location : chr " "
## .. ..$ publicUseAuthCode : chr "OPEN"
## .. ..$ ownerTypeId : chr "DNR"
## .. ..$ lakeAccessComments: chr " "
## ..$ lakeName : chr "East Leaf"
## ..$ DOWNumber : chr "56011602"
## ..$ waterClarity : chr [1, 1:2] "08/02/2010" "5"
## ..$ meanDepthFeet : int 0
## ..$ maxDepthFeet : int 47
## $ message : chr "Normal execution."