Search code examples
pythonhtmlxpathextract

I want to extract a text from html page which has two types of class


I want to extract shipping fees from the html page. But there are two types of html pages from which I need to extract the shipping fees.

for one page the Xpath is

//*[@class="flex flex-row justify-between f6 mid-gray pt2"]//div[2]/text()

for another page the Xpath is

//*[@class="mid-gray flex items-center"]//span/text()

Now I want to combine the above Xpaths as one so that if any one of the condition met it should extract the value (https://i.sstatic.net/wIRWp.png) (https://i.sstatic.net/9PqU3.png)


Solution

  • try this:

    (//*[@class="flex flex-row justify-between f6 mid-gray pt2"]/div[@class="green"]
    |
    //*[@class="mid-gray flex items-center"]/span)[1]/text()
    

    Explanation:

    Surround the two with () and the | combines the two, and [1] selects the first of those two