Home > Mobile >  How to find text within page if it is in different variation?
How to find text within page if it is in different variation?

Time:06-04

I have an element for example <span id="tdo_8">7 650 €</span> and I need to find this element by price, but the problem is that I do not know in what form the price will be. I need to make my search for this substring in element reinforced so it does not have problems in any scenario. For example if I search for price of 7650 it will not find this element, but if I search for 7 650(notice the space) then it will find it with no issues. For now I'm using search by xpath //*[contains(text(),'{search_price}')]. My question - is there any way I can improve this search for any price for ANY page I throw at it?

P.S. I'm using scrapy with no javascript rendered webpages.

CodePudding user response:

This code will work for you:

response.xpath("//*[contains(translate(text(),' ',''),'7650')]").getall()

This will return all the elements that contain 7650 - with or without space, with or without $, €, etc.

I have tested this with:

<span  id="tdo_8">7 650 €</span>
<span  id="tdo_8">7 650 </span>
<span  id="tdo_8">$ 7650</span>
<span  id="tdo_8">7650.30</span> 
  • Related