【发布时间】:2017-04-25 03:24:20
【问题描述】:
为什么下面两个代码 sn-ps 给出不同的输出?它们之间的唯一区别是第一种情况下的h1 标记在第二种情况下被替换为h 标记。这是因为h1标签在html中有特殊的“含义”吗?我尝试使用h1 到h6,它们都将[] 作为输出,而使用h7 它开始将[u'xxx'] 作为输出。
from scrapy import Selector # scrapy version: 1.2.2
text = '<h1><p>xxx</p></h1>'
print Selector(text=text).xpath('//h1/p/text()').extract()
Output[1]: []
text = '<h><p>xxx</p></h>'
print Selector(text=text).xpath('//h/p/text()').extract()
Output[2]: [u'xxx']
【问题讨论】:
标签: python html xpath scrapy selector