scrapy-如何停止重定向(302)

我正在尝试使用Scrapy抓取网址。但这会将我重定向到不存在的页面。

Redirecting (302) to <GET http://www.shop.inonit.in/mobile/Products/Inonit-Home-Decor--Knick-Knacks-Cushions/Shor-Sharaba/Andaz-Apna-Apna-Cushion-Cover/1275197> from <GET http://www.shop.inonit.in/Products/Inonit-Home-Decor--Knick-Knacks-Cushions/Shor-Sharaba/Andaz-Apna-Apna-Cushion-Cover/pid-1275197.aspx>

问题是http://www.shop.inonit.in/Products/Inonit-Home-Decor--Knick-Knacks-Cushions/Shor-Sharaba/Andaz-Apna-Apna-Cushion-Cover/pid-1275197.aspx存在,但http://www.shop.inonit.in/mobile/Products/Inonit-Home-Decor--Knick-Knacks-Cushions/Shor-Sharaba/Andaz-Apna-Apna-Cushion-Cover/1275197却没有,所以搜寻器找不到这个。我也爬过许多其他网站,但在其他任何地方都没有这个问题。有什么办法可以阻止此重定向?

任何帮助将非常感激。谢谢。

更新:这是我的spider课

class Inon_Spider(BaseSpider):

name = 'Inon'

allowed_domains = ['www.shop.inonit.in']

start_urls = ['http://www.shop.inonit.in/Products/Inonit-Gadget-Accessories-Mobile-Covers/-The-Red-Tag/Samsung-Note-2-Dead-Mau/pid-2656465.aspx']

def parse(self, response):

item = DealspiderItem()

hxs = HtmlXPathSelector(response)

title = hxs.select('//div[@class="aboutproduct"]/div[@class="container9"]/div[@class="ctl_aboutbrand"]/h1/text()').extract()

price = hxs.select('//span[@id="ctl00_ContentPlaceHolder1_Price_ctl00_spnWebPrice"]/span[@class="offer"]/span[@id="ctl00_ContentPlaceHolder1_Price_ctl00_lblOfferPrice"]/text()').extract()

prc = price[0].replace("Rs. ","")

description = []

item['price'] = prc

item['title'] = title

item['description'] = description

item['url'] = response.url

return item

回答:

你可以简单地通过添加诸如

meta={'dont_redirect': True}

你也可以停止针对特定响应代码的重定向,例如

 meta={'dont_redirect': True,"handle_httpstatus_list": [302]}

它将停止仅重定向302响应代码。

        yield Request('some url',

meta = {

'dont_redirect': True,

'handle_httpstatus_list': [302]

},

callback= self.some_call_back)

以上是 scrapy-如何停止重定向(302) 的全部内容, 来源链接: utcz.com/qa/434933.html

回到顶部