Scrapy skips some html elements

I used scrapy to get some book data on amazon.com. I just want the name, author and book prices. I want to do this in categories, for example, books on computer science.

consider a piece of code (some Amazon page):

<div class="a-row">
::before
    <div class="a-column a-span7">
         <div class="a-row a-spacing-none">...</div>
         <div class="a-row a-spacing-none">...</div>
         <hr class="a-divider-normal s-result-divier">
         <div class="a-row a-spacing-none">...</div>
         <div class="a-row a-spacing-none">...</div>
         <div class="a-row a-spacing-none">...</div>
    </div>
    <div class="a-column a-span5 a-span-last"></div>
::after
</div>

So, I tried to get the div elements inside the div [@ class = "a-column a-span7"]. But only the first two div elements are returned. The command I used was:

>>> books = response.selector.xpath ('.//div[@class="a-fixed-left-grid-col a-col-right"]')
>>> abook = books[0].xpath('.//div[@class="a-row"]')
>>> prices = abook.xpath ('.//div[@class="a-column a-span7"]')
>>> len (prices.xpath('div'))
2

The above code does the following:

  • Get all div elements containing book information on a specific page
  • Get the first “book” and get a div that contains the prices of the book.
  • Get div with class a-column a-span7 '
  • Here's the problem: I don't understand why the number of div elements inside a div with a-column a-span7 'class

div <hr> , , scrapy stop on tag <hr> . , :

>>> abook.xpath ('div')
[<Selector xpath='div' data=u'<div class="a-column a-span7"><div class'>, <Selector xpath='div' data=u'<div class="a-column a-span5 a-span-last'>]

, . , .

: stackref. use < <hr> , .

+4
1

, , user agent . - :

scrapy shell "http://www.amazon.com.br/s/ref=lp_12008582011_nr_n_2?fst=as%3Aoff&rh=n%3A6740748011%2Cn%3A%218169561011%2Cn%3A%218169562011%2Cn%3A12008582011%2Cn%3A12008596011&bbn=12008582011&ie=UTF8&qid=1448202280&rnid=12008582011" -s USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
+2

Source: https://habr.com/ru/post/1616916/


All Articles