import scrapy
from ..items import CentriItem
from scrapy_playwright.page import PageMethod
class NikespiderSpider(scrapy.Spider):
name = 'nikespider'
def start_requests(self):
url = "https://www.nike.com/ch/en/w/mens-nik1?q=shirts"
yield scrapy.Request(url, meta=dict(
playwright=True,
playwright_include_page=True,
playwright_page_methods=[
PageMethod("wait_for_selector", ".product-card__link-overlay"),
PageMethod("evaluate", "window.scrollBy(0, document.body.scrollHeight)"),
PageMethod("wait_for_selector",".css-c2ovjx:nth-child(25) .product-card__link-overlay"),
]
))
async def parse(self, response):
page = response.meta["playwright_page"]
await page.close()
i = 0
for link in response.css(".product-card__link-overlay::attr(href)"):
i = i + 1
print(i)
async def parse_items(self, response,link):
pass
这是我的代码刮耐克。网址,我刮有无限滚动。它加载24个项目在第一次,你向下滚动后,它加载24多。我试图添加这个功能使用scrapy剧作家,但它是不工作。有人能帮助我吗?
1条答案
按热度按时间oaxa6hgo1#
看起来从他们的api中提取数据可能会更容易。
第一页的输出如下所示: