python link to the database, the data is written

import requests
from bs4 import BeautifulSoup
from lxml import etree
import pymysql
print('连接到mysql服务器...')
db = pymysql.connect(
        host="localhost",
        user="root",
        passwd="root",
        port=3306,
        db="dbh",
        charset = ' UTF8 ' , 
        cursorClass = pymysql.cursors.DictCursor)
 Print ( ' connected on! ' ) 
Cursor = db.cursor ()

First is to link the incoming information

Then set the set, and the value of the variable own variables, the last set of parameters to be passed to the database

insert_color = ("INSERT INTO for_health(id,problem,introduce,solution,problem_id,drug,paqu_address,is_infect,symptom,cure_rate)" "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)")
dese = (id,problem,introduce,solution,problem_id,drug,paqu_address,is_infect,symptom,cure_rate)
cursor.execute(insert_color, dese)
db.commit()

This is inside the id, problem yourself and other parameters are set, sql but also according to their own situation to write your own, then the incoming data information, and finally commit to submit

 

Guess you like

Origin www.cnblogs.com/zhaochunhui/p/11331760.html