gpt4 book ai didi

python - 用Scrapy抓取ajax页面?

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:55 24 4
gpt4 key购买 nike

我正在使用 Scrapy 从此页面抓取数据

https://www.bricoetloisirs.ch/magasins/gardena

产品列表动态显示。查找获取产品的网址

https://www.bricoetloisirs.ch/coop/ajax/nextPage/(cpgnum=1&layout=7.01-14_180_69_164_182&uiarea=2&carea=%24ROOT&fwrd=frwd0&cpgsize=12)/.do?page=2&_=1473841539272

但是当我用 Scrapy 抓取它时,它给了我空白页面

<span class="pageSizeInformation" id="page0" data-page="0" data-pagesize="12">Page: 0 / Size: 12</span>

这是我的代码

# -*- coding: utf-8 -*-
import scrapy

from v4.items import Product


class GardenaCoopBricoLoisirsSpider(scrapy.Spider):
name = "Gardena_Coop_Brico_Loisirs_py"

start_urls = [
'https://www.bricoetloisirs.ch/coop/ajax/nextPage/(cpgnum=1&layout=7.01-14_180_69_164_182&uiarea=2&carea=%24ROOT&fwrd=frwd0&cpgsize=12)/.do?page=2&_=1473841539272'
]

def parse(self, response):
print response.body

最佳答案

我解决了这个问题。

# -*- coding: utf-8 -*-
import scrapy

from v4.items import Product


class GardenaCoopBricoLoisirsSpider(scrapy.Spider):
name = "Gardena_Coop_Brico_Loisirs_py"

start_urls = [
'https://www.bricoetloisirs.ch/magasins/gardena'
]

def parse(self, response):
for page in xrange(1, 50):
url = response.url + '/.do?page=%s&_=1473841539272' % page
yield scrapy.Request(url, callback=self.parse_page)

def parse_page(self, response):
print response.body

关于python - 用Scrapy抓取ajax页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39486224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com