组织
我有来自的下一页按钮元素 this page ,
<li class="Pagination-item Pagination-item--next Pagination-item--nextSolo "> <button type="button" class="Pagination-link js-veza-stranica kist-FauxAnchor" data-page="2" data-href="https://www.njuskalo.hr/prodaja-kuca?page=2" role="link">SljedeÄa <span aria-hidden="true" role="presentation">»</span></button> </li>
data-href
代码
response.xpath('//*[@id="form_browse_detailed_search"]/div/div[1]/div[5]/div[1]/nav/ul/li[8]/button').extract_first()
我找回,
'<button type="button" class="Pagination-link js-veza-stranica" data-page="2">SljedeÄa\xa0<span aria-hidden="true" role="presentation">»</span></button>'
问题:
火车在哪里 数据href
数据href
无论如何,解决这个问题的一种方法是基于 data-page 属性:
data-page
from w3lib.url import add_or_replace_parameter ... next_page = response.css('.Pagination-item--nextSolo button::attr(data-page)').get() next_page_url = add_or_replace_parameter(response.url, 'page', next_page)
w3lib 是一个开源库: https://github.com/scrapy/w3lib
w3lib