python spider xpath获取具体信息

得到整个网页后,我们要从中截取有效信息,即使用xpath。

在回调函数里,做一些修改:

1
2
3
4
5
6
7
8
9
10
11
def (self, response):
card_real_amt = '//td[@id="cardRealAmt"]'
print response.xpath(card_real_amt + '/text()').extract()[0] # 数组
print response.xpath(card_real_amt + '/../td[2]/text()').extract()[0]
print response.xpath(card_real_amt + '/../td[4]/text()').extract()[0]
pass

打印结果:

1
2
3
卡内余额(截止到2018-05-11 19:31:31):
698474623
4.20