2017-08-30 16 views
1

まず私は、特定の売り手の行を取得するには、CSSを使用して、私は現在のノードを参照するには「./」を使う私は、XPathと売り手のdivのscrap cssセレクタチェーン現在のノードを表現する方法は?

を取得したいこのurl

を考えると、私は(5)を得ることができますターゲットdiv(行)の直後に配置されるdivs。 Bの

b = response.css('div#olpOfferList div.a-row.a-spacing-mini.olpOffer')[1].xpath('./div') 

結果:

<Selector xpath='./div' data=u'<div class="a-column a-span2 olpPriceCol'> 
<Selector xpath='./div' data=u'<div class="a-column a-span3 olpConditio'> 
<Selector xpath='./div' data=u'<div class="a-column a-span3 olpDelivery'> 
<Selector xpath='./div' data=u'<div class="a-column a-span2 olpSellerCo'> 
<Selector xpath='./div' data=u'<div class="a-column a-span2 olpBuyColum'> 

が、CSSで、私は、現在のノード

a = response.css('div#olpOfferList div.a-row.a-spacing-mini.olpOffer')[1].css('div > div') 

結果選択した後、現在のノードを参照することはありませんか:

<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-column a-span2 olpPriceCol'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-column a-span3 olpConditio'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-section a-spacing-small">\n'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-column a-span3 olpDelivery'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-column a-span2 olpSellerCo'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-column a-span2 olpBuyColum'> 
<Selector xpath=u'descendant-or-self::div/div' data=u'<div class="a-button-stack">\n   '> 

私はこれを試しましたが、エラーが発生しましたr:

a = response.css('div#olpOfferList div.a-row.a-spacing-mini.olpOffer')[1].css('> div') 

どのように私は現在のノードをCSSで参照できますか? :D助けてくれてありがとう!

答えて

1

最後にXPATHセレクタがなければ、これを行うことはできません。

だから、あなたが使用しているものCSSは現在のノードまたは親ノードを参照する方法がありませんので、あなただけのXPathを使用する必要があります

b = response.css('div#olpOfferList div.a-row.a-spacing-mini.olpOffer')[1].xpath('./div') 

正しいです。

+0

私のパズルを明確にしてくれてありがとう! – Tianqing

関連する問題