简体   繁体   中英

Using Css Selectors or xpath to extract data in scrapy

Am trying to get the value from this link: view-source: https://www.otomoto.pl/ajax/misc/contact/multi_phone/6CLxXv/0/

the wanted values is: 42 677 17 00 i entered the scrapy shell then used: response.css('td.line-content::text').extract() and i got [] as a result.

i then tried with xpath: response.xpath('/html/body/table/tbody/tr/td[2]/text()').extract() and i got [] as a result.

why is it am not getting the wanted result, is there something am messing here?

I hope this may help you.

In [159]: response.xpath('//p/descendant-or-self::p[1]/text()').extract()[0].split(':')[1].split('}')[0]                                                                           
Out[159]: '"42 677 17 00"'

In [160]: print(response.xpath('//p/descendant-or-self::p[1]/text()').extract()[0].split(':')[1].split('}')[0])                                                                    
"42 677 17 00"

In [161]: print(response.xpath('//p/text()').extract()[0].split(':')[1].split('}')[0])                                                                                             
"42 677 17 00"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM