【发布时间】:2020-09-09 15:02:48
【问题描述】:
我正在尝试抓取以下网站:
我成功地抓取了第一页,但我无法进入下一页。这有两个原因:
-
检查
next_page按钮时,我没有得到相对或绝对值 网址。相反,我得到了JavaScript:getPage(2),我无法使用它来关注链接 -
下一页按钮链接可以通过
(//table[@class='tbl_pagination']//a//@href)[11]访问时 在第一页,但从第 2 页开始,下一页按钮是第 12 项, 即(//table[@class='tbl_pagination']//a//@href)[12]
所以最终我的问题是,我如何有效地转到所有后续页面并抓取数据。
这可能很容易解决,但我是网络抓取的初学者,因此感谢任何反馈。请看下面我的代码。
感谢您的帮助。
**
import scrapy
from scrapy_selenium import SeleniumRequest
class WinesSpider(scrapy.Spider):
name = 'wines'
def start_requests(self):
yield SeleniumRequest(
url='https://www.getwines.com/category_Wine',
wait_time=3,
callback=self.parse
)
def parse(self, response):
products = response.xpath("(//div[@class='layMain']//tbody)[5]/tr ")
for product in products:
yield {
'product_name':
product.xpath(".//a[@class='Srch-producttitle']/text()").get(),
'product_link':
product.xpath(".//a[@class='Srch-producttitle']/@href").get(),
'product_actual_price':
product.xpath(".//td//td[3]//td/span[2]/text()").get(),
'product_price_onsale':
product.xpath(".//td//td[3]//td/span[4]/text()").get()
}
#next_page = response.xpath("(//table[@class='tbl_pagination']//a//@href)[11]").get()
#if next_page:
# absolute_url = f"'https://www.getwines.com/category_Wine"**
【问题讨论】:
标签: javascript selenium post pagination scrapy