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