from urllib.request import urlopen from bs4 import BeautifulSoup import re import os import requests import pymysql #数据库插入 def INSERTDATA(title,url): conn = pymysql.connect(host='172.16.0.230', port=3306, user='root', passwd='@嘻嘻嘻', database='scrapy',charset='utf8') # 使用cursor()方法获取操作游标 cur = conn.cursor() sql2 = "insert into urls(title,url) values('{}','{}')" sql=sql2.format(title,url) cur.execute(sql) # 提交 conn.commit() cur.close() conn.close()