Search code examples
htmlrtextextractrselenium

How can I extract this text from HTML, using RSelenium?


I want to scrape the 57, but if I'm only able to get the Text that says Search Result

this is the code that i use to grab the element with RSelenium

element<- remDr$findElements(using = 'id','resultListHeadingName') 
lapply(element,function (x) x$getElementText()) %>% unlist()

this is the output

[1] "Search Results:"

this is the HTML text from the Website

<h1 class="page-title alt selectorgadget_selected" xpath="1">
            <span id="resultListHeadingName" class="color-p2">Search Results:</span> 1 - 50 of 57   </h1>

Solution

  • Find the parent:

    element<- remDr$findElements(using = 'xpath', "//*[@id='resultListHeadingName']/..")
    lapply(element,function (x) x$getElementText()) %>% unlist()