Xpath + Scrapy + Python : data point couldn't be scraped

This is the XML structure:

<tr>
   <td>
       <font size="3">
           <strong>Location:</strong> 
           Hiranandani Gardens, Powai
       </font>
   </td> 
</tr>  

I want to extract : Hiranandani Gardens, Powai

I tried with these:

response.xpath('//font[@size="3"]/strong[text()="Location:"]/text()').extract()

response.xpath('//font[@size="3"]/strong[text()="Location:"]').extract()

Both returned an empty list.

Note: we must have to use the text of tag, i.e., "Location:". Otherwise, there are many other places on the site where the same XML structure is used. So, it'll fetch many more unnecessary things apart from the desired value if the text of strong tag is not used.

1 answer

  • answered 2018-09-19 07:03 Andersson

    Try below XPath to get required output

    //font[@size="3" and normalize-space(strong)="Location:"]/text()