First experience of Scrapy and first experience of Scrapy

Source: Internet
Author: User

First experience of Scrapy and first experience of Scrapy

The development environment of python2 and python3 is installed in the previous section.

Step 1: Enter the development environment, workon article_spider

Enter this environment:

When installing Scrapy, some errors occur during the installation process: these errors are usually caused by the absence of installation of some files. Because these errors often occur in college, it is very practical to solve this problem, directly to http://www.lfd.uci.edu /~ Download the corresponding file from the gohlke/pythonlibs/website, and install it with pip. The specific process is not described in detail.

Then go to the project directory and open our new virtual environment:

Create a scrapy project: ArticleSpider

Create a project framework: import it in pycharm

 

Scrapy. cfg: configuration file of the project.
ArticleSpeder/: python module of the project. Then you will add the code here.
ArticleSpeder/items. py: The item file in the project.
ArticleSpeder/pipelines. py: pipelines file in the project.
ArticleSpeder/settings. py: the setting file of the project.
ArticleSpeder/spiders/: directory where spider code is stored.

Return to the dos window and use basic to create a template.

The above pycharm has been created:

For better development in the future, create a main. py class for debugging.

This is the code content

Import sys to set the project directory, the call command will take effect

It is best not to write the path in it to the dead: the path can be obtained through the OS, more flexible

Execute is used to execute

Jobbole. py content

The xpath technology is used to obtain the field information of the corresponding article, including the title, time, number of comments, and number of likes.

Writing this article, we know that every time we debug and trouble in pycharm, we can use scrapy shell for debugging because Scrapy is large.

Mark the address of the target Website: now we can perform debugging more happily.

This is the first experience of scrapy today.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.