How to use contains() in Xpath selectors

13 views
Skip to first unread message

Kurt Peek

unread,
Jul 18, 2016, 4:42:34 AM7/18/16
to scrapy-users

Dear Scrapy community,

I’m trying to scrape web pages such as http://www.funda.nl/koop/amsterdam/huis-49826458-buiksloterdijk-270/ which contain a <dt> element containing the text “Vraagprijs” (=”listing price” in Dutch). If I 

scrapy shell http://www.funda.nl/koop/amsterdam/huis-49826458-buiksloterdijk-270/


and then


In [1]: response.xpath('//dt')

Out[1]: 

[<Selector xpath='//dt' data=u'<dt>Vraagprijs</dt>'>,

 <Selector xpath='//dt' data=u'<dt>Aangeboden sinds</dt>'>,

 <Selector xpath='//dt' data=u'<dt>Status</dt>'>,


I get several matches (only the first few are shown). Suppose I want to select the one with "Vraagprijs" inside. I've tried

response.xpath('//dt[contains(.//text(),'Vraagprijs')]')

but I get an error message SyntaxError: invalid syntax. Any ideas what is going wrong?

Best,
Kurt

Luis Miguel Morillas

unread,
Jul 18, 2016, 4:58:48 AM7/18/16
to scrapy...@googlegroups.com
response.xpath('//dt[contains(.//text(),"Vraagprijs")]')


Saludos,

-- luismiguel (@lmorillas)
> --
> You received this message because you are subscribed to the Google Groups
> "scrapy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scrapy-users...@googlegroups.com.
> To post to this group, send email to scrapy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/scrapy-users.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages