(eight) crawl data using MySQL Store

Source: Internet
Author: User
Tags mysql command line

First, download phpstudy from the official website and other pre-preparation

CMD in

Pip Install Pymysql

Start Phpstudy,apache and MySQL after running "Other options Menu"-"MySQL Tool"-"MySQL command line"

Password is root

This is used in SQL language, remember to add a semicolon after the statement.

show databases;

Then create the table

CREATE table good (id int (+) auto_increment primary key,title varchar (+), link varchar, comment varchar (100));

Database Creation Complete

Second, the pipelines.py and the database to link

Finally garbled out finally solved!

which used the

Set names GBK;

It is equivalent to the following three-sentence instruction:

SET character_set_client = GBK; SET character_set_results = GBK; SET character_set_connection = GBK;

So the output of Chinese will not garbled!

Give the complete pipelines.py

Import Pymysqlclass Dangdang2pipeline (object):    def process_item (self, item, spider):        conn=pymysql.connect ( Host= "127.0.0.1", user= "root", passwd= "root", db= "Dangdang", charset= "UTF8") for        I in range (len (item["title")):            title=item["title"][i]            #.encode (' UTF8 ')            link=item["link"][i]            comment=item["comment"][i]            # Print (title,link,comment)            sql= "insert into good (title,link,comment) values ('%s ', '%s ', '%s ');"% ( title,link,comment)            #print (SQL)            conn.query (SQL)        conn.close ()        return item

(eight) crawl data using MySQL Store

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.