使用scrapy抓取简单网站时出现503 Service Unavailable错误

时间:2020-04-26 07:28:04

标签: python web-scraping scrapy

我写了一个简单的代码来抓取网站,但即使覆盖USER_AGENT却出现了503 Service Unavailable错误,但还是出现同样的错误,请您指导我如何解决此问题, 这是我的代码:

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


class CurtainSpider(scrapy.Spider):
    name = 'curtain'
    allowed_domains = ['https://www.redbubble.com/shop']
    #start_urls = ['https://www.redbubble.com/shop/shower-curtains/']
    def start_requests(self):
        yield scrapy.Request(url='https://www.redbubble.com/shop/shower-curtains/', callback=self.parse, headers={
            'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36'
        })

    def parse(self, response):
        products = response.xpath("//div[@class='styles__grid--197Ps']/a")
        for product in products:
            title = product.xpath(".//div[@class='styles__box--206r9 styles__paddingRight-0--fzRHs']/div[@class='styles__textContainer--1xehi styles__disableLineHeight--3n9Fg styles__nowrap--2Vk3A']/span/text()").get()
            yield {
                'Title' : title
            }

0 个答案:

没有答案