locked
Capture an attribute of the span-class (HTML) RRS feed

  • Question

  • I am trying to pull the price of an item from a site. I can get the title of the item but cant seem to get the price.

    Attached is what I have so far. How can I get the "content" attribute?

    HTML:

    <div class="price__wrapper">
      <span id="ajaxPrice" class="pReg" itemprop="price" content="28.97">
       <span class="price__currency">$</span>
       <span class="price__dollars">
                                        28
                                    </span>
       <span class="price__cents">97</span>
      </span>
    </div>

    Code:

    $data = invoke-webrequest -uri "https://www.homedepot.com/p/Kwikset-Tustin-Satin-Nickel-Privacy-Bed-Bath-Door-Lever-730TNL-15-6AL-RCS/202106308?keyword=734509&semanticToken=20330000111_20200116123136340521_x6z5+20330000111+%3E++cnn%3A%7B11%3A0%7D+cnr%3A%7B7%3A0%7D+cnd%3A%7B4%3A0%7D+cne%3A%7B8%3A0%7D+cnb%3A%7B0%3A0%7D+cns%3A%7B5%3A0%7D+cnx%3A%7B3%3A0%7D+st%3A%7B734509%7D%3Ast+oos%3A%7B0%3A1%7D+dln%3A%7B562872%7D+qu%3A%7B734509%7D%3Aqu"
    
    $data.ParsedHtml.all.tags("h1") | ForEach-Object -MemberName innertext
    
    $data.ParsedHtml.getElementById("ajaxPrice") | ForEach-Object -MemberName innertext  #this works but no period between the dollar and cents -- and acts as three separate data point

    Saturday, January 18, 2020 1:04 AM

Answers

  • $url = 'https://www.homedepot.com/p/Kwikset-Tustin-Satin-Nickel-Privacy-Bed-Bath-Door-Lever-730TNL-15-6AL-RCS/202106308?keyword=734509&semanticToken=20330000111_20200116123136340521_x6z5+20330000111+%3E++cnn%3A%7B11%3A0%7D+cnr%3A%7B7%3A0%7D+cnd%3A%7B4%3A0%7D+cne%3A%7B8%3A0%7D+cnb%3A%7B0%3A0%7D+cns%3A%7B5%3A0%7D+cnx%3A%7B3%3A0%7D+st%3A%7B734509%7D%3Ast+oos%3A%7B0%3A1%7D+dln%3A%7B562872%7D+qu%3A%7B734509%7D%3Aqu'
    $data = invoke-webrequest $url
    $price = $data.ParsedHtml.getElementById('ajaxPrice')
    $price.getAttribute('content')



    \_(ツ)_/

    • Marked as answer by Dustin2810 Saturday, January 18, 2020 1:27 PM
    Saturday, January 18, 2020 9:46 AM

All replies

  • What is your error?  WHat value are you asking for in MemberName.

    Without an accurate and complete question there is no way to understand what is not working.


    \_(ツ)_/

    Saturday, January 18, 2020 1:43 AM
  • I am trying to get the "content" value from the HTML. So I want it to print out 28.97.

    <span id="ajaxPrice" class="pReg" itemprop="price" content="28.97">

    I am not sure how to get this attributes value. 

    Saturday, January 18, 2020 1:53 AM
  • You have to get the element by its ID and then get the content.  The "content" is an attribute and not a property.


    \_(ツ)_/

    Saturday, January 18, 2020 2:03 AM
  • Review this object to see what is available.

    Without a URL there is really no way to advise on this.


    \_(ツ)_/

    Saturday, January 18, 2020 2:05 AM
  • I have

    $data.ParsedHtml.getElementById("ajaxPrice")

    I assume this is correct... 

    I dont know how to get the attribute "content". Can you show me an example? 

    Saturday, January 18, 2020 2:06 AM
  • Can you not see my original code I posted? it has the URL and code I had already created... 

    URL - 

    https://www.homedepot.com/p/Kwikset-Tustin-Satin-Nickel-Privacy-Bed-Bath-Door-Lever-730TNL-15-6AL-RCS/202106308?keyword=734509&semanticToken=20330000111_20200116123136340521_x6z5+20330000111+%3E++cnn%3A%7B11%3A0%7D+cnr%3A%7B7%3A0%7D+cnd%3A%7B4%3A0%7D+cne%3A%7B8%3A0%7D+cnb%3A%7B0%3A0%7D+cns%3A%7B5%3A0%7D+cnx%3A%7B3%3A0%7D+st%3A%7B734509%7D%3Ast+oos%3A%7B0%3A1%7D+dln%3A%7B562872%7D+qu%3A%7B734509%7D%3Aqu
    Saturday, January 18, 2020 2:09 AM
  • $url = 'https://www.homedepot.com/p/Kwikset-Tustin-Satin-Nickel-Privacy-Bed-Bath-Door-Lever-730TNL-15-6AL-RCS/202106308?keyword=734509&semanticToken=20330000111_20200116123136340521_x6z5+20330000111+%3E++cnn%3A%7B11%3A0%7D+cnr%3A%7B7%3A0%7D+cnd%3A%7B4%3A0%7D+cne%3A%7B8%3A0%7D+cnb%3A%7B0%3A0%7D+cns%3A%7B5%3A0%7D+cnx%3A%7B3%3A0%7D+st%3A%7B734509%7D%3Ast+oos%3A%7B0%3A1%7D+dln%3A%7B562872%7D+qu%3A%7B734509%7D%3Aqu'
    $data = invoke-webrequest $url
    $price = $data.ParsedHtml.getElementById('ajaxPrice')
    $price.getAttribute('content')



    \_(ツ)_/

    • Marked as answer by Dustin2810 Saturday, January 18, 2020 1:27 PM
    Saturday, January 18, 2020 9:46 AM