首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >排除要抓取的元素

问排除要抓取的元素
EN

Stack Overflow用户
提问于 2016-07-10 04:18:07
回答 0查看 591关注 0票数 2

我正在尝试从列表中排除某些元素。

在http://www.persimmonhomes.com/rooley-park-10126页面上,有我想要删除的元素(div class="housetype js-filter-housetype"),还有一些我不想删除的元素(div class="housetype js-filter-housetype“style="display: none;")

html看起来像这样:

代码语言:javascript
复制
<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;“。

我当前的代码是:

代码语言:javascript
复制
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;")) --但到目前为止还没有成功。

我能请教一下你的想法吗?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38285989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档