How to obtain the href element using RSelenium from this code?

我与影子孤独终老i 提交于 2021-01-28 05:44:42

问题


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=" 
{&quot;description&quot;:&quot;title&quot;}" 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=" 
     {&quot;description&quot;:&quot;subtitle&quot;}" 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!