使用 Inspector Gadget 失败的选项卡抓取 RSelenium 站点
Scrape RSelenium site with tabs where Inspector Gadget fails
此站点有一个 table(保证投资证书 - 长期和复利),在单击选项卡(不可兑现 GIC)后出现。
我的计划是通过 id 找到标签,点击它然后获取 HTML 源。
然后,我通常使用 read_html
和 html_nodes
来接近我正在搜索的项目。在这种情况下,非注册和注册(TFSA、RSP、RIF、RESP)的费率。
但是,带有 Chrome 的 Inspector Gadget 在网站上冻结,所以我不确定要使用什么 css 选择器。关于如何获得保证投资证书利率的任何想法 - 长期和复利 table?
# TD GIC scrape - FAIL
remDr$navigate("https://www.td.com/ca/en/personal-banking/products/saving-investing/gic-rates-canada/")
# Find element, click element and then get source
webElem <- remDr$findElement(using = "id", "Tab_non-cashable")
webElem$clickElement()
html <- remDr$getPageSource()[[1]]
read_html(html) %>% # parse HTML
html_nodes("td-complex-chart")
# {xml_nodeset (0)}
下面是我的解决方案:
library(Rselenium)
driver <- rsDriver(browser=c("firefox"), port = 4567L)
remote_driver <- driver[["client"]]
remote_driver$navigate("https://www.td.com/ca/en/personal-banking/products/saving-investing/gic-rates-canada/")
webElem <- remote_driver$findElement(using = "xpath", '//*[@id="Tab_non-cashable"]')
webElem$clickElement()
之后你可以拿走你的 table。
下面是关于如何获得保证投资证书-长期和单利的想法
webElem <- remote_driver$findElement(using = "css selector", 'section.ng-scope:nth-child(7) > div:nth-child(1)')
webElem$getElementText()
[[1]]
[1] "Guaranteed Investment Certificate - Long-Term and Simple Interest\nTerm\nNon-registered and Registered (TFSA, RSP, RIF, RESP)\n1 year\n0.45%\n2 years\n0.50%\n3 years\n0.60%\n4 years\n0.70%\n5 years\n0.85%"
什么时候可以,我建议您使用xpath
来单独设置您需要的部分。
此站点有一个 table(保证投资证书 - 长期和复利),在单击选项卡(不可兑现 GIC)后出现。
我的计划是通过 id 找到标签,点击它然后获取 HTML 源。
然后,我通常使用 read_html
和 html_nodes
来接近我正在搜索的项目。在这种情况下,非注册和注册(TFSA、RSP、RIF、RESP)的费率。
但是,带有 Chrome 的 Inspector Gadget 在网站上冻结,所以我不确定要使用什么 css 选择器。关于如何获得保证投资证书利率的任何想法 - 长期和复利 table?
# TD GIC scrape - FAIL
remDr$navigate("https://www.td.com/ca/en/personal-banking/products/saving-investing/gic-rates-canada/")
# Find element, click element and then get source
webElem <- remDr$findElement(using = "id", "Tab_non-cashable")
webElem$clickElement()
html <- remDr$getPageSource()[[1]]
read_html(html) %>% # parse HTML
html_nodes("td-complex-chart")
# {xml_nodeset (0)}
下面是我的解决方案:
library(Rselenium)
driver <- rsDriver(browser=c("firefox"), port = 4567L)
remote_driver <- driver[["client"]]
remote_driver$navigate("https://www.td.com/ca/en/personal-banking/products/saving-investing/gic-rates-canada/")
webElem <- remote_driver$findElement(using = "xpath", '//*[@id="Tab_non-cashable"]')
webElem$clickElement()
之后你可以拿走你的 table。
下面是关于如何获得保证投资证书-长期和单利的想法
webElem <- remote_driver$findElement(using = "css selector", 'section.ng-scope:nth-child(7) > div:nth-child(1)')
webElem$getElementText()
[[1]]
[1] "Guaranteed Investment Certificate - Long-Term and Simple Interest\nTerm\nNon-registered and Registered (TFSA, RSP, RIF, RESP)\n1 year\n0.45%\n2 years\n0.50%\n3 years\n0.60%\n4 years\n0.70%\n5 years\n0.85%"
什么时候可以,我建议您使用xpath
来单独设置您需要的部分。