Extract text from all
  • tag contains tag with text SKU
  • I want to Extract text from all li tag contains tag with text SKU.

    <li> 5.875 x 5.875</li>
    <li><b>SKU</b>:        1TVN-11</li>
    <li>based name</li>
    <li>based name1</li>
    <li>based name2</li>

    From above I want to extract the text “1TVN-11” but sometimes this li tag is not present. I am using XPath right now:

    SKU = root.xpath("./ul/li/b[.='SKU']/following-sibling::text()[1]")


    What I would do if li is not all the time there :


    // stand for recursive expression

    Leave a Reply

    Your email address will not be published. Required fields are marked *