parent
8c23b9045d
commit
4bdec52046
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,7 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.11 (pythonProject)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (pythonProject)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/豆瓣读书250爬虫_20220926.iml" filepath="$PROJECT_DIR$/.idea/豆瓣读书250爬虫_20220926.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.11 (pythonProject)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,195 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Awesome-pyecharts</title>
|
||||||
|
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
|
||||||
|
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/themes/shine.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body >
|
||||||
|
<div id="66cf902e378046b4a9673c317f195451" class="chart-container" style="width:800px; height:600px; "></div>
|
||||||
|
<script>
|
||||||
|
var chart_66cf902e378046b4a9673c317f195451 = echarts.init(
|
||||||
|
document.getElementById('66cf902e378046b4a9673c317f195451'), 'shine', {renderer: 'canvas'});
|
||||||
|
var option_66cf902e378046b4a9673c317f195451 = {
|
||||||
|
"animation": true,
|
||||||
|
"animationThreshold": 2000,
|
||||||
|
"animationDuration": 1000,
|
||||||
|
"animationEasing": "cubicOut",
|
||||||
|
"animationDelay": 0,
|
||||||
|
"animationDurationUpdate": 300,
|
||||||
|
"animationEasingUpdate": "cubicOut",
|
||||||
|
"animationDelayUpdate": 0,
|
||||||
|
"aria": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"type": "bar",
|
||||||
|
"name": "\u8bc4\u5206",
|
||||||
|
"legendHoverLink": true,
|
||||||
|
"data": [
|
||||||
|
"9.3",
|
||||||
|
"9.3",
|
||||||
|
"9.3",
|
||||||
|
"9.3",
|
||||||
|
"9.4",
|
||||||
|
"9.4",
|
||||||
|
"9.5",
|
||||||
|
"9.5",
|
||||||
|
"9.6",
|
||||||
|
"9.7"
|
||||||
|
],
|
||||||
|
"realtimeSort": false,
|
||||||
|
"showBackground": false,
|
||||||
|
"stackStrategy": "samesign",
|
||||||
|
"cursor": "pointer",
|
||||||
|
"barMinHeight": 0,
|
||||||
|
"barCategoryGap": "20%",
|
||||||
|
"barGap": "30%",
|
||||||
|
"large": false,
|
||||||
|
"largeThreshold": 400,
|
||||||
|
"seriesLayoutBy": "column",
|
||||||
|
"datasetIndex": 0,
|
||||||
|
"clip": true,
|
||||||
|
"zlevel": 0,
|
||||||
|
"z": 2,
|
||||||
|
"label": {
|
||||||
|
"show": true,
|
||||||
|
"margin": 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"legend": [
|
||||||
|
{
|
||||||
|
"data": [
|
||||||
|
"\u8bc4\u5206"
|
||||||
|
],
|
||||||
|
"selected": {},
|
||||||
|
"show": true,
|
||||||
|
"padding": 5,
|
||||||
|
"itemGap": 10,
|
||||||
|
"itemWidth": 25,
|
||||||
|
"itemHeight": 14,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"borderColor": "#ccc",
|
||||||
|
"borderRadius": 0,
|
||||||
|
"pageButtonItemGap": 5,
|
||||||
|
"pageButtonPosition": "end",
|
||||||
|
"pageFormatter": "{current}/{total}",
|
||||||
|
"pageIconColor": "#2f4554",
|
||||||
|
"pageIconInactiveColor": "#aaa",
|
||||||
|
"pageIconSize": 15,
|
||||||
|
"animationDurationUpdate": 800,
|
||||||
|
"selector": false,
|
||||||
|
"selectorPosition": "auto",
|
||||||
|
"selectorItemGap": 7,
|
||||||
|
"selectorButtonGap": 10
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tooltip": {
|
||||||
|
"show": true,
|
||||||
|
"trigger": "item",
|
||||||
|
"triggerOn": "mousemove|click",
|
||||||
|
"axisPointer": {
|
||||||
|
"type": "line"
|
||||||
|
},
|
||||||
|
"showContent": true,
|
||||||
|
"alwaysShowContent": false,
|
||||||
|
"showDelay": 0,
|
||||||
|
"hideDelay": 100,
|
||||||
|
"enterable": false,
|
||||||
|
"confine": false,
|
||||||
|
"appendToBody": false,
|
||||||
|
"transitionDuration": 0.4,
|
||||||
|
"textStyle": {
|
||||||
|
"fontSize": 14
|
||||||
|
},
|
||||||
|
"borderWidth": 0,
|
||||||
|
"padding": 5,
|
||||||
|
"order": "seriesAsc"
|
||||||
|
},
|
||||||
|
"xAxis": [
|
||||||
|
{
|
||||||
|
"show": true,
|
||||||
|
"scale": false,
|
||||||
|
"nameLocation": "end",
|
||||||
|
"nameGap": 15,
|
||||||
|
"gridIndex": 0,
|
||||||
|
"axisLabel": {
|
||||||
|
"show": true,
|
||||||
|
"rotate": 0,
|
||||||
|
"margin": 8
|
||||||
|
},
|
||||||
|
"inverse": false,
|
||||||
|
"offset": 0,
|
||||||
|
"splitNumber": 5,
|
||||||
|
"minInterval": 0,
|
||||||
|
"splitLine": {
|
||||||
|
"show": true,
|
||||||
|
"lineStyle": {
|
||||||
|
"show": true,
|
||||||
|
"width": 1,
|
||||||
|
"opacity": 1,
|
||||||
|
"curveness": 0,
|
||||||
|
"type": "solid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"yAxis": [
|
||||||
|
{
|
||||||
|
"show": true,
|
||||||
|
"scale": false,
|
||||||
|
"nameLocation": "end",
|
||||||
|
"nameGap": 15,
|
||||||
|
"gridIndex": 0,
|
||||||
|
"inverse": false,
|
||||||
|
"offset": 0,
|
||||||
|
"splitNumber": 5,
|
||||||
|
"minInterval": 0,
|
||||||
|
"splitLine": {
|
||||||
|
"show": true,
|
||||||
|
"lineStyle": {
|
||||||
|
"show": true,
|
||||||
|
"width": 1,
|
||||||
|
"opacity": 1,
|
||||||
|
"curveness": 0,
|
||||||
|
"type": "solid"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"data": [
|
||||||
|
"\u4e09\u56fd\u6f14\u4e49\uff08\u5168\u4e8c\u518c\uff09",
|
||||||
|
"\u52a8\u7269\u519c\u573a",
|
||||||
|
"\u98d8",
|
||||||
|
"\u767e\u5e74\u5b64\u72ec",
|
||||||
|
"1984",
|
||||||
|
"\u6d3b\u7740",
|
||||||
|
"\u91ce\u8349",
|
||||||
|
"\u4e09\u4f53\u5168\u96c6",
|
||||||
|
"\u7ea2\u697c\u68a6",
|
||||||
|
"\u54c8\u5229\u00b7\u6ce2\u7279"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": [
|
||||||
|
{
|
||||||
|
"show": true,
|
||||||
|
"text": "\u8bc4\u5206\u524d10\u699c",
|
||||||
|
"target": "blank",
|
||||||
|
"subtarget": "blank",
|
||||||
|
"left": "center",
|
||||||
|
"bottom": "bottom",
|
||||||
|
"padding": 5,
|
||||||
|
"itemGap": 10,
|
||||||
|
"textAlign": "auto",
|
||||||
|
"textVerticalAlign": "auto",
|
||||||
|
"triggerEvent": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
chart_66cf902e378046b4a9673c317f195451.setOption(option_66cf902e378046b4a9673c317f195451);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -0,0 +1,161 @@
|
|||||||
|
import copy
|
||||||
|
import re
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import pandas as pd
|
||||||
|
from time import sleep
|
||||||
|
import sql
|
||||||
|
|
||||||
|
|
||||||
|
class Book:
|
||||||
|
def __init__(self, name, url, star, star_people, author, translater, publisher, pub_year, price, comment):
|
||||||
|
self.name = name
|
||||||
|
self.url = url
|
||||||
|
self.star = star
|
||||||
|
self.star_people = star_people
|
||||||
|
self.author = author
|
||||||
|
self.translater = translater
|
||||||
|
self.publisher = publisher
|
||||||
|
self.pub_year = pub_year
|
||||||
|
self.price = price
|
||||||
|
self.comment = comment
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
'书名': self.name,
|
||||||
|
'豆瓣链接': self.url,
|
||||||
|
'作者': self.author,
|
||||||
|
'译者': self.translater,
|
||||||
|
'出版社': self.publisher,
|
||||||
|
'出版日期': self.pub_year,
|
||||||
|
'价格': self.price,
|
||||||
|
'评分': self.star,
|
||||||
|
'评分人数': self.star_people,
|
||||||
|
'一句话评价': self.comment
|
||||||
|
}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Book Info: {self.name} - {self.author} - {self.pub_year} - {self.publisher} - {self.price} - {self.star} - {self.star_people} - {self.comment}"
|
||||||
|
|
||||||
|
|
||||||
|
class DoubanBookTop250Crawler:
|
||||||
|
def __init__(self):
|
||||||
|
self.book_list = []
|
||||||
|
self.book_list_data=[]
|
||||||
|
|
||||||
|
def get_book_info(self, url, headers):
|
||||||
|
res = requests.get(url, headers=headers)
|
||||||
|
soup = BeautifulSoup(res.text, 'html.parser')
|
||||||
|
for book in soup.select('.item'):
|
||||||
|
name = book.select('.pl2 a')[0]['title'] # 书名
|
||||||
|
url = book.select('.pl2 a')[0]['href'] # 书籍链接
|
||||||
|
star = book.select('.rating_nums')[0].text # 书籍评分
|
||||||
|
star_people = book.select('.pl')[1].text # 评分人数
|
||||||
|
# 提取其他字段
|
||||||
|
info = book.select('.pl')[0].text.split('/')
|
||||||
|
if len(info) == 5: # 正常情况
|
||||||
|
author = info[0]
|
||||||
|
translater = info[1]
|
||||||
|
publisher = info[2]
|
||||||
|
pub_year = info[3]
|
||||||
|
price = info[4]
|
||||||
|
elif len(info) == 4: # 没有译者
|
||||||
|
author = info[0]
|
||||||
|
translater = None
|
||||||
|
publisher = info[1]
|
||||||
|
pub_year = info[2]
|
||||||
|
price = info[3]
|
||||||
|
elif len(info) == 6: # 有2个价格
|
||||||
|
author = info[0]
|
||||||
|
translater = info[1]
|
||||||
|
publisher = info[2]
|
||||||
|
pub_year = info[3]
|
||||||
|
price = str(info[4]) + '/' + str(info[5])
|
||||||
|
elif len(info) == 3: # 没有作者,且没有译者
|
||||||
|
author = None
|
||||||
|
translater = None
|
||||||
|
publisher = info[0]
|
||||||
|
pub_year = info[1]
|
||||||
|
price = str(info[2])
|
||||||
|
else:
|
||||||
|
# 这里可以加入错误处理逻辑,比如打印错误信息
|
||||||
|
continue # 跳过当前循环
|
||||||
|
comment = book.select('.quote span')[0].text if book.select('.quote span') else None # 一句话评价
|
||||||
|
book_comment = book.select('.quote span')[0].text if book.select('.quote span') else None # 一句话评价
|
||||||
|
book_obj = Book(name, url, star, star_people, author, translater, publisher, pub_year, price, book_comment)
|
||||||
|
self.book_list.append(book_obj.to_dict())
|
||||||
|
self.book_list_data.append(book_obj)
|
||||||
|
|
||||||
|
|
||||||
|
def save_to_csv(self, csv_name):
|
||||||
|
df = pd.DataFrame(self.book_list)
|
||||||
|
df.to_csv(csv_name, encoding='utf_8_sig', index=False)
|
||||||
|
|
||||||
|
def crawl_douban_top250(self):
|
||||||
|
headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
|
||||||
|
for i in range(3):
|
||||||
|
page_url = 'https://book.douban.com/top250?start={}'.format(str(i * 25))
|
||||||
|
print('开始爬取第{}页,地址是:{}'.format(str(i + 1), page_url))
|
||||||
|
self.get_book_info(page_url, headers)
|
||||||
|
sleep(1)
|
||||||
|
self.save_to_csv(csv_name="BookDouban250.csv")
|
||||||
|
|
||||||
|
# 实例化爬虫对象,并调用方法执行爬取和保存数据
|
||||||
|
crawler = DoubanBookTop250Crawler()
|
||||||
|
crawler.crawl_douban_top250()
|
||||||
|
book_list = crawler.book_list
|
||||||
|
book_list_data = crawler.book_list_data
|
||||||
|
dataexcel={"书名":[],"豆瓣链接":[],"作者":[],"译者":[],"出版社":[],"出版日期":[],"价格":[],"评分":[],"评分人数":[],"一句话评价":[]}
|
||||||
|
for book in book_list:
|
||||||
|
book['评分人数']= book['评分人数'].replace('\n', '').strip()
|
||||||
|
book['评分人数'] = book['评分人数'].replace(' ', '').replace("(","").replace(")","").strip()
|
||||||
|
dataexcel['书名'].append(book['书名'])
|
||||||
|
dataexcel['豆瓣链接'].append(book['豆瓣链接'])
|
||||||
|
dataexcel['作者'].append(book['作者'])
|
||||||
|
dataexcel['译者'].append(book['译者'])
|
||||||
|
dataexcel['出版社'].append(book['出版社'])
|
||||||
|
dataexcel['出版日期'].append(book['出版日期'])
|
||||||
|
dataexcel['价格'].append(book['价格'])
|
||||||
|
dataexcel['评分'].append(book['评分'])
|
||||||
|
dataexcel['评分人数'].append(book['评分人数'])
|
||||||
|
dataexcel['一句话评价'].append(book['一句话评价'])
|
||||||
|
book_list_data_two_price=[]
|
||||||
|
for book in book_list_data:
|
||||||
|
book.star_people=book.star_people.replace('\n','').strip()
|
||||||
|
book.star_people=book.star_people.replace(' ','').replace("(","").replace(")","").strip()
|
||||||
|
book.star_people=''.join(filter(str.isdigit, book.star_people))
|
||||||
|
book.price=book.price.replace('元','').strip()
|
||||||
|
if book.price.find('/')!=-1:
|
||||||
|
copy_price=book.price.split('/')[1]
|
||||||
|
book.price=book.price.split('/')[0]
|
||||||
|
copy_book=copy.deepcopy(book)
|
||||||
|
copy_book.price=copy_price
|
||||||
|
book_list_data_two_price.append(copy_book)
|
||||||
|
match=re.search(r'\d+\.\d{2}',book.price)
|
||||||
|
if match:
|
||||||
|
book.price = match.group()
|
||||||
|
book_list_data=book_list_data+book_list_data_two_price
|
||||||
|
|
||||||
|
|
||||||
|
print(crawler.book_list)
|
||||||
|
# 将 book_list 转换为 DataFrame
|
||||||
|
df = pd.DataFrame(dataexcel)
|
||||||
|
# 将 DataFrame 写入到 Excel 文件
|
||||||
|
file_name = 'book_data.xlsx'
|
||||||
|
df.to_excel(file_name, index=False)
|
||||||
|
print(f"书籍数据已写入到 {file_name}")
|
||||||
|
|
||||||
|
# 使用BookDatabase类
|
||||||
|
db = sql.BookDatabase(host='localhost', user='root', password='123456', database='xiaosuo', table_name='books')
|
||||||
|
db.initialize_table()
|
||||||
|
db.insert_books(book_list_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,226 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Awesome-pyecharts</title>
|
||||||
|
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body >
|
||||||
|
<div id="f91b113d26d04dc99f3a0df5c9667820" class="chart-container" style="width:900px; height:500px; "></div>
|
||||||
|
<script>
|
||||||
|
var chart_f91b113d26d04dc99f3a0df5c9667820 = echarts.init(
|
||||||
|
document.getElementById('f91b113d26d04dc99f3a0df5c9667820'), 'white', {renderer: 'canvas'});
|
||||||
|
var option_f91b113d26d04dc99f3a0df5c9667820 = {
|
||||||
|
"animation": true,
|
||||||
|
"animationThreshold": 2000,
|
||||||
|
"animationDuration": 1000,
|
||||||
|
"animationEasing": "cubicOut",
|
||||||
|
"animationDelay": 0,
|
||||||
|
"animationDurationUpdate": 300,
|
||||||
|
"animationEasingUpdate": "cubicOut",
|
||||||
|
"animationDelayUpdate": 0,
|
||||||
|
"aria": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"color": [
|
||||||
|
"blue",
|
||||||
|
"green",
|
||||||
|
"yellow",
|
||||||
|
"red",
|
||||||
|
"purple"
|
||||||
|
],
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"type": "pie",
|
||||||
|
"colorBy": "data",
|
||||||
|
"legendHoverLink": true,
|
||||||
|
"selectedMode": false,
|
||||||
|
"selectedOffset": 10,
|
||||||
|
"clockwise": true,
|
||||||
|
"startAngle": 90,
|
||||||
|
"minAngle": 0,
|
||||||
|
"minShowLabelAngle": 0,
|
||||||
|
"avoidLabelOverlap": true,
|
||||||
|
"stillShowZeroSum": true,
|
||||||
|
"percentPrecision": 2,
|
||||||
|
"showEmptyCircle": true,
|
||||||
|
"emptyCircleStyle": {
|
||||||
|
"color": "lightgray",
|
||||||
|
"borderColor": "#000",
|
||||||
|
"borderWidth": 0,
|
||||||
|
"borderType": "solid",
|
||||||
|
"borderDashOffset": 0,
|
||||||
|
"borderCap": "butt",
|
||||||
|
"borderJoin": "bevel",
|
||||||
|
"borderMiterLimit": 10,
|
||||||
|
"opacity": 1
|
||||||
|
},
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"name": " \u4eba\u6c11\u6587\u5b66\u51fa\u7248\u793e ",
|
||||||
|
"value": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u4f5c\u5bb6\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u5317\u4eac\u5341\u6708\u6587\u827a\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u91cd\u5e86\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u5357\u6d77\u51fa\u7248\u516c\u53f8 ",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u8bd1\u6797\u51fa\u7248\u793e ",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u4e0a\u6d77\u8bd1\u6587\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u5317\u4eac\u8054\u5408\u51fa\u7248\u516c\u53f8 ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u7fa4\u4f17\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u751f\u6d3b\u00b7\u8bfb\u4e66\u00b7\u65b0\u77e5\u4e09\u8054\u4e66\u5e97 ",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u54c8\u5c14\u6ee8\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u5929\u6d25\u4eba\u6c11\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u4e2d\u56fd\u6d77\u5173\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": " \u4e2d\u56fd\u9752\u5e74\u51fa\u7248\u793e ",
|
||||||
|
"value": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"radius": [
|
||||||
|
"0%",
|
||||||
|
"75%"
|
||||||
|
],
|
||||||
|
"center": [
|
||||||
|
"50%",
|
||||||
|
"50%"
|
||||||
|
],
|
||||||
|
"label": {
|
||||||
|
"show": true,
|
||||||
|
"margin": 8,
|
||||||
|
"formatter": "{b}: {c}"
|
||||||
|
},
|
||||||
|
"labelLine": {
|
||||||
|
"show": true,
|
||||||
|
"showAbove": false,
|
||||||
|
"length": 15,
|
||||||
|
"length2": 15,
|
||||||
|
"smooth": false,
|
||||||
|
"minTurnAngle": 90,
|
||||||
|
"maxSurfaceAngle": 90
|
||||||
|
},
|
||||||
|
"rippleEffect": {
|
||||||
|
"show": true,
|
||||||
|
"brushType": "stroke",
|
||||||
|
"scale": 2.5,
|
||||||
|
"period": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"legend": [
|
||||||
|
{
|
||||||
|
"data": [
|
||||||
|
" \u4eba\u6c11\u6587\u5b66\u51fa\u7248\u793e ",
|
||||||
|
" \u4f5c\u5bb6\u51fa\u7248\u793e ",
|
||||||
|
" \u5317\u4eac\u5341\u6708\u6587\u827a\u51fa\u7248\u793e ",
|
||||||
|
" \u91cd\u5e86\u51fa\u7248\u793e ",
|
||||||
|
" \u5357\u6d77\u51fa\u7248\u516c\u53f8 ",
|
||||||
|
" \u8bd1\u6797\u51fa\u7248\u793e ",
|
||||||
|
" \u4e0a\u6d77\u8bd1\u6587\u51fa\u7248\u793e ",
|
||||||
|
" \u5317\u4eac\u8054\u5408\u51fa\u7248\u516c\u53f8 ",
|
||||||
|
" \u7fa4\u4f17\u51fa\u7248\u793e ",
|
||||||
|
" \u751f\u6d3b\u00b7\u8bfb\u4e66\u00b7\u65b0\u77e5\u4e09\u8054\u4e66\u5e97 ",
|
||||||
|
" \u54c8\u5c14\u6ee8\u51fa\u7248\u793e ",
|
||||||
|
" \u5929\u6d25\u4eba\u6c11\u51fa\u7248\u793e ",
|
||||||
|
" \u4e2d\u56fd\u6d77\u5173\u51fa\u7248\u793e ",
|
||||||
|
" \u4e2d\u56fd\u9752\u5e74\u51fa\u7248\u793e "
|
||||||
|
],
|
||||||
|
"selected": {},
|
||||||
|
"show": true,
|
||||||
|
"padding": 5,
|
||||||
|
"itemGap": 10,
|
||||||
|
"itemWidth": 25,
|
||||||
|
"itemHeight": 14,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"borderColor": "#ccc",
|
||||||
|
"borderRadius": 0,
|
||||||
|
"pageButtonItemGap": 5,
|
||||||
|
"pageButtonPosition": "end",
|
||||||
|
"pageFormatter": "{current}/{total}",
|
||||||
|
"pageIconColor": "#2f4554",
|
||||||
|
"pageIconInactiveColor": "#aaa",
|
||||||
|
"pageIconSize": 15,
|
||||||
|
"animationDurationUpdate": 800,
|
||||||
|
"selector": false,
|
||||||
|
"selectorPosition": "auto",
|
||||||
|
"selectorItemGap": 7,
|
||||||
|
"selectorButtonGap": 10
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tooltip": {
|
||||||
|
"show": true,
|
||||||
|
"trigger": "item",
|
||||||
|
"triggerOn": "mousemove|click",
|
||||||
|
"axisPointer": {
|
||||||
|
"type": "line"
|
||||||
|
},
|
||||||
|
"showContent": true,
|
||||||
|
"alwaysShowContent": false,
|
||||||
|
"showDelay": 0,
|
||||||
|
"hideDelay": 100,
|
||||||
|
"enterable": false,
|
||||||
|
"confine": false,
|
||||||
|
"appendToBody": false,
|
||||||
|
"transitionDuration": 0.4,
|
||||||
|
"textStyle": {
|
||||||
|
"fontSize": 14
|
||||||
|
},
|
||||||
|
"borderWidth": 0,
|
||||||
|
"padding": 5,
|
||||||
|
"order": "seriesAsc"
|
||||||
|
},
|
||||||
|
"title": [
|
||||||
|
{
|
||||||
|
"show": true,
|
||||||
|
"text": "\u51fa\u7248\u5546\u5206\u5e03\u997c\u56fe",
|
||||||
|
"target": "blank",
|
||||||
|
"subtarget": "blank",
|
||||||
|
"padding": 5,
|
||||||
|
"itemGap": 10,
|
||||||
|
"textAlign": "auto",
|
||||||
|
"textVerticalAlign": "auto",
|
||||||
|
"triggerEvent": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
chart_f91b113d26d04dc99f3a0df5c9667820.setOption(option_f91b113d26d04dc99f3a0df5c9667820);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,11 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
msg = input('我:')
|
||||||
|
sess = requests.get(
|
||||||
|
('https://open.drea.cc/bbsapi/chat/get?keyWord=' + msg + '&userName=type%3Dbbs'))
|
||||||
|
js = sess.text
|
||||||
|
js = json.loads(js)
|
||||||
|
print('微梦机器人:', js['data']['reply'])
|
@ -0,0 +1,69 @@
|
|||||||
|
import pymysql
|
||||||
|
|
||||||
|
class BookDatabase:
|
||||||
|
def __init__(self, host, user, password, database, table_name):
|
||||||
|
self.host = host
|
||||||
|
self.user = user
|
||||||
|
self.password = password
|
||||||
|
self.database = database
|
||||||
|
self.table_name = table_name
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
self.connection = pymysql.connect(host=self.host, user=self.user, password=self.password,
|
||||||
|
database=self.database, cursorclass=pymysql.cursors.DictCursor)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.connection.close()
|
||||||
|
|
||||||
|
def table_exists(self):
|
||||||
|
with self.connection.cursor() as cursor:
|
||||||
|
check_table_query = f"SHOW TABLES LIKE '{self.table_name}'"
|
||||||
|
cursor.execute(check_table_query)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
return bool(result)
|
||||||
|
|
||||||
|
def create_table(self):
|
||||||
|
with self.connection.cursor() as cursor:
|
||||||
|
create_table_query = """
|
||||||
|
CREATE TABLE IF NOT EXISTS books (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
url VARCHAR(255),
|
||||||
|
star FLOAT,
|
||||||
|
star_people INT,
|
||||||
|
author VARCHAR(255),
|
||||||
|
translater VARCHAR(255),
|
||||||
|
publisher VARCHAR(255),
|
||||||
|
pub_year VARCHAR(20),
|
||||||
|
price FLOAT,
|
||||||
|
comment TEXT
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
cursor.execute(create_table_query)
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
|
def insert_books(self, booklist):
|
||||||
|
with self.connection.cursor() as cursor:
|
||||||
|
insert_query = """
|
||||||
|
INSERT INTO{table_name} (name, url, star, star_people, author, translater, publisher, pub_year, price, comment)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
|
"""
|
||||||
|
for book in booklist:
|
||||||
|
cursor.execute(insert_query.format(table_name=self.table_name),
|
||||||
|
(book.name, book.url, float(book.star), int(book.star_people),
|
||||||
|
book.author, book.translater, book.publisher,
|
||||||
|
book.pub_year, float(book.price), book.comment))
|
||||||
|
self.connection.commit()
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def initialize_table(self):
|
||||||
|
|
||||||
|
self.connect()
|
||||||
|
if not self.table_exists():
|
||||||
|
self.create_table()
|
||||||
|
# self.close()
|
||||||
|
|
||||||
|
|
||||||
|
# # 使用BookDatabase类
|
||||||
|
# db = BookDatabase(host='localhost', user='root', password='123456', database='xiaosuo', table_name='books')
|
||||||
|
# db.initialize_table()
|
Loading…
Reference in new issue