python - how to extract this information as one node in xpath1.0? -


<a href="../legislation/legislation.aspx?id=62397"><span style="cursor:pointer;" title="weight = 2">expiry date</span> + 5 years</a> 

how extract data expiry data+ 5 years in 1 line code?

response.xpath('//tr[@style="cursor:pointer;"]/td[1]/a/span/text() | //tr[@style="cursor:pointer;"]/td[1]/a/text()').extract() 

returns 2 elements expiry code , +5 days

and works on table means there many herfs this, , each 1 want concat information

[u'expiry date', u' + 5 years', u'due date', u' + 4 years', u'creation', u' + 3 years'] want [expiry date+ 5 years, due date+4 years, creation+3 years] lot

you can join of text nodes inside a:

"".join(response.xpath("//a[contains(@href, 'legislation')]//text()").extract()) 

demo:

$ scrapy shell index.html in [1]: "".join(response.xpath("//a[contains(@href, 'legislation')]//text()").extract()) out[1]: u'expiry date + 5 years' 

Comments