我在试着从https://www.kff.org/interactive/subsidy-calculator那里获取信息。例如,放置state=California,zip=90001,income=20000,无覆盖,1人,1成人,无儿童,age=21,无烟草。
我想得到“估计的财务帮助”和“你的银色计划的费用”的数字(它们在“结果”灰色框中以蓝色粗体显示,由于某种原因,我无法上传屏幕截图)。当我对数字使用xpath时,我得到的结果是空字符串。如果我要检索一些其他文本(不在灰色框中),情况就不是这样了。我想知道这会有什么问题。我附加了下面的代码。如果这是一个愚蠢的问题,请原谅我,因为我对网络抓取非常陌生。谢谢!
state = tolower('CA')
zip = 94704
income = 20000
people = 1
adult = 1
children = 0
url = paste0("https://www.kff.org/interactive/subsidy-calculator/#state=", state, "&zip=", zip, "&income-type=dollars&income=", income, "&employer-coverage=0&people=", people, "&alternate-plan-family=individual&adult-count=", adult, "&adults%5B0%5D%5Bage%5D=21&adults%5B0%5D%5Btobacco%5D=0&child-count=", children)
# This returns empty string
r = read_html(url) %>%
html_nodes(xpath ='//*[@id="subsidy-calculator-new"]/div[5]/div/div/dl/dd[1]/span') %>% html_text()
# This returns "Number of children (20 and younger) enrolling in Marketplace coverage", a line that's not in the grey box.
r = read_html(url) %>%
html_nodes(xpath = '//*[@id="subsidy-form"]/div[2]/div[3]/div[3]/p') %>%
html_text()https://stackoverflow.com/questions/56313196
复制相似问题