Capture an attribute of the span-class (HTML)

Welcome Forums General PowerShell Q&A Capture an attribute of the span-class (HTML)

Viewing 2 reply threads
  • Author
    Posts
    • #198668
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      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?

      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
      • This topic was modified 2 months, 1 week ago by SeaAndSand16.
      • This topic was modified 2 months, 1 week ago by SeaAndSand16.
    • #198734
      Participant
      Topics: 0
      Replies: 14
      Points: 116
      Rank: Participant

      Hi,

      This works for me:

      $data.ParsedHtml.getElementById("ajaxPrice").getAttribute("content")
      28.97

      Regards,

      Stuart.

    • #198746
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      thanks, this worked! I think I was forgetting the “get” in getAttribute when I was doing this earlier.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.