我正在尝试从列表中排除某些元素。
在http://www.persimmonhomes.com/rooley-park-10126页面上,有我想要删除的元素(div class="housetype js-filter-housetype"),还有一些我不想删除的元素(div class="housetype js-filter-housetype“style="display: none;")
html看起来像这样:
<div class="housetype js-filter-housetype">
<div class="housetype js-filter-housetype">
<div class="housetype js-filter-housetype">
<div class="housetype js-filter-housetype">
<div class="housetype js-filter-housetype">
<div class="housetype js-filter-housetype" style="display: none;">
<div class="housetype js-filter-housetype" style="display: none;">我正在尝试编写代码来排除div显示“housetype js-class=-housetype”style="display: none;“。
我当前的代码是:
start_urls = [
"http://www.persimmonhomes.com/rooley-park-10126",
]
def parse(self, response):
for sel in response.xpath('//*[@id="aspnetForm"]/div[4]'):
item = PersimmonItem()
item['housetypeheading'] = sel.xpath('//*[@class="houses-list js-scrollable js-filterable js-houselist"]//*[not(@style="display: none;")]/h2[@class="housetype__heading"]').extract()
yield item到目前为止,这还不起作用。它只是丢弃所有的元素,不管它是否有这个部分(style="display: none;")。我也尝试过not(contains(@style,"display: none;")) --但到目前为止还没有成功。
我能请教一下你的想法吗?
https://stackoverflow.com/questions/38285989
复制相似问题