library(RSelenium)
library(rvest)
shell('docker run -d -p 4446:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4446L, browserName = "firefox")
remDr$open()
remDr$navigate("https://fdc.nal.usda.gov/fdc-app.html#/food-details/2237774/nutrients")
Sys.sleep(10)
html_Text <- remDr$getPageSource()[[1]]
(read_html(html_Text) %>% html_table())[[1]]
# A tibble: 42 x 29
Name Amount Unit Data ~1 Deriv~2 n Samples Min Max Median Lab M~3 Footn~4 Last ~5 `` `` ``
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <lgl> <lgl> <lgl> <chr>
1 Energy 4 kcal UNKNOWN "Calcu~ "" "Sampl~ "Ana~ Anal~ Analy~ Analys~ NA NA NA NA Amou~
2 Analysis ~ Analy~ Anal~ Analys~ "" "" "" "" NA NA NA NA NA NA NA NA
3 Amount/10~ Unit Tech~ Method "City" "Sta~ "Acqui~ "FDC~ NA NA NA NA NA NA NA NA
4 Protein 0.83 g UNKNOWN "Calcu~ "" "Sampl~ "Ana~ Anal~ Analy~ Analys~ NA NA NA NA Amou~
5 Analysis ~ Analy~ Anal~ Analys~ "" "" "" "" NA NA NA NA NA NA NA NA
6 Amount/10~ Unit Tech~ Method "City" "Sta~ "Acqui~ "FDC~ NA NA NA NA NA NA NA NA
7 Total lip~ 0 g UNKNOWN "Calcu~ "" "Sampl~ "Ana~ Anal~ Analy~ Analys~ NA NA NA NA Amou~
8 Analysis ~ Analy~ Anal~ Analys~ "" "" "" "" NA NA NA NA NA NA NA NA
9 Amount/10~ Unit Tech~ Method "City" "Sta~ "Acqui~ "FDC~ NA NA NA NA NA NA NA NA
10 Carbohydr~ 0.42 g UNKNOWN "Calcu~ "" "Sampl~ "Ana~ Anal~ Analy~ Analys~ NA NA NA NA Amou~
# ... with 32 more rows, 13 more variables: `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>,
# `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, `` <lgl>, and abbreviated variable names
# 1: `Data Prov. Deriv. Method`, 2: `Deriv. By`, 3: `Lab Method`, 4: Footnote, 5: `Last Updated`
# i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
1条答案
按热度按时间bjp0bcyl1#
我已经能够用下面的代码得到表: