【发布时间】:2021-04-05 15:48:31
【问题描述】:
我想提取本网页右上角表格中的值:
https://www.timeanddate.de/wetter/deutschland/karlsruhe/klima
(Wärmster Monat:VALUE,Kältester Monat:VALUE,Jahresniederschlag:VALUE)
不幸的是,如果我使用 html_nodes("Selectorgadgets result for the specific value"),我会收到链接顶部表格的值:
https://www.timeanddate.de/stadt/info/deutschland/karlsruhe
(网页类似,如果您点击顶部栏上的“Uhrzeit/Übersicht”,您将访问第二页和表格,如果您点击“Wetter”-->“Klima”,您将访问第一页/表格(我想从中提取值的那个!)
num_link= "https://www.timeanddate.de/wetter/deutschland/Karlsruhe/klima"
num_page= read_html(num_link)
rain_year = num_page %>% html_nodes("#climateTable > div.climate-month.climate-month--allyear > div:nth-child(3) > p:nth-child(1)") %>% html_text()
temp_warm = num_page %>% html_nodes("#climateTable > div.climate-month.climate-month--allyear > div:nth-child(2) > p:nth-child(1)") %>% html_text()
temp_cold = num_page %>% html_nodes("#climateTable > div.climate-month.climate-month--allyear > div:nth-child(2) > p:nth-child(1)") %>% html_text()
我得到每个变量的“字符(空)”。 :(
提前致谢!
【问题讨论】:
-
我很困惑,因为您似乎在说您这样做并且您不想要右上角的表格。你想要顶部还是底部?
标签: html r web-scraping rvest