Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Creating a project in pycharm using scrapy

tutorial/
    scrapy.cfg            # deploy configuration file

    tutorial/             # project's Python module, you'll import your code from here
        __init__.py

        items.py          # project items definition file

        middlewares.py    # project middlewares file

        pipelines.py      # project pipelines file

        settings.py       # project settings file

        spiders/          # a directory where you'll later put your spiders
            __init__.py
Comment

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}')
Comment

PREVIOUS NEXT
Code Example
Python :: python staticmethod property 
Python :: find array length in python 
Python :: freecodecamp python 
Python :: optimize images using pillow 
Python :: binary to octal in python 
Python :: how to make a python program on odd and even 
Python :: binary tree in python 
Python :: box plot in seaborn 
Python :: math module in python 
Python :: pandas dataframe drop rows with -ve in column value 
Python :: sort dict 
Python :: listas en python 
Python :: making ckeditor django responsive 
Python :: **kwargs in python 
Python :: find highest value in array python 
Python :: python list all columns in dataframe 
Python :: multi threading in python for 2 different functions with return 
Python :: create a database in python 
Python :: read list stored as a string with pandas read csv 
Python :: how to check if python is installed on mac 
Python :: rename colums dataframe pandas 
Python :: how to remove a list of numbers from a list in python 
Python :: python concatenate strings 
Python :: Matplotlib add text to axes 
Python :: django render example 
Python :: tic tac toe minimax 
Python :: head first python by paul barry pdf 
Python :: python - caéculate the average based on the level of a second column in a df 
Python :: tensorflow evaluation metrics 
Python :: argparse flag without value 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =