问题
I am using Rselenium to obtain an URL, and I don't understand why is not working.
My code:
links <- remDr$findElements(using = "xpath", value = "//*[@class
=
'item-info']")
final_link <- data.frame(link = unlist(sapply(links, function(x)
{x$getElementAttribute('href')})))
The code of the page:
<div class="item-info">
<p class="title product-field" translate="no" data-track-info="
{"description":"title"}" data-force-track="">
<a href="https://www.kobo.com/us/en/ebook/added-youth"
class="">Added Youth</a>
</p>
<p class="subtitle product-field" translate="no" data-track-info="
{"description":"subtitle"}" data-force-track="">
<a href="https://www.kobo.com/us/en/ebook/added-youth" class="">All Natural Anti-Aging Program</a>
</p>
The expected result is the link, in this case: https://www.kobo.com/us/en/ebook/added-youth
回答1:
My code:
page <- read_html(paste0(urls1[[i]]))
links <- page %>%
html_nodes("a") %>%
html_attr("href")
来源:https://stackoverflow.com/questions/55670026/how-to-obtain-the-href-element-using-rselenium-from-this-code