所以我使用 scrapy 从亚马逊图书部分抓取数据。但不知何故我知道它有一些动态数据。我想知道如何从网站中提取动态数据。到目前为止我已经尝试过以下方法:
import scrapy
from ..items import AmazonsItem
class AmazonSpiderSpider(scrapy.Spider):
name = 'amazon_spider'
start_urls = ['https://www.amazon.in/s?k=agatha+christie+books&crid=3MWRDVZPSKVG0&sprefix=agatha%2Caps%2C269&ref=nb_sb_ss_i_1_6']
def parse(self, response):
items = AmazonsItem()
products_name = response.css('.s-access-title::attr("data-attribute")').extract()
for product_name in products_name:
print(product_name)
next_page = response.css('li.a-last a::attr(href)').get()
if next_page is not None:
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page, callback=self.parse)
Run Code Online (Sandbox Code Playgroud)
现在我使用 SelectorGadget 来选择一个我必须抓取的类,但对于动态网站,它不起作用。