Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

Creating a project in pycharm using scrapy

import scrapy


class QuotesSpider(scrapy.Spider):
    name = "quotes"

    def start_requests(self):
        urls = [
            'http://quotes.toscrape.com/page/1/',
            'http://quotes.toscrape.com/page/2/',
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        page = response.url.split("/")[-2]
        filename = f'quotes-{page}.html'
        with open(filename, 'wb') as f:
            f.write(response.body)
        self.log(f'Saved file {filename}')
Source by docs.scrapy.org #
 
PREVIOUS NEXT
Tagged: #Creating #project #pycharm #scrapy
ADD COMMENT
Topic
Name
1+6 =