之前爬取部分代码被用作爬取智联招聘信息,故有误未重视。
此部分代码将MySQL数据库中已经爬取下来的数据调用plotly包进行可视化展示。
import plotly
import pymysql
connect = pymysql.Connect(host="localhost",user="root",password="1984ispb",db="TianmaoMilkPowder",port=3306,charset="utf8")
cursor = connect.cursor()
sql = "SELECT Price,goodsName,Place FROM powderdata"
cursor.execute(sql)
rows = cursor.fetchall()
x_data = []
y_data = []
price_data=[]
for row in rows:
x_data.append(row[2])
y_data.append(row[1])
price_data.append(row[0])
data = [
{
'x':x_data,
'y':y_data,
'mode':'marker',
'marker':{
'size':x_data
}
}
]
plotly.offline.plot(data,filename='powder_show.html')