master
parent
d12e7dc982
commit
bad777ad6c
@ -0,0 +1,61 @@ |
|||||||
|
import json |
||||||
|
import os |
||||||
|
import time |
||||||
|
|
||||||
|
import django |
||||||
|
import requests |
||||||
|
import threading |
||||||
|
from bs4 import BeautifulSoup |
||||||
|
|
||||||
|
from PixivSearch.settings import logger |
||||||
|
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings") |
||||||
|
django.setup() |
||||||
|
from PixivSearch.model.config import mediaInfo, stat |
||||||
|
|
||||||
|
current_mediaInfo = mediaInfo(id=0, chn_name='null') |
||||||
|
flag = True |
||||||
|
|
||||||
|
|
||||||
|
class bangumi(threading.Thread): |
||||||
|
begin = 0 |
||||||
|
end = 0 |
||||||
|
id = 0 |
||||||
|
|
||||||
|
def __init__(self, begin, end): |
||||||
|
threading.Thread.__init__(self) |
||||||
|
self.begin = begin |
||||||
|
self.end = end |
||||||
|
|
||||||
|
def save(self): |
||||||
|
req = requests.get("https://www.bilibili.com/bangumi/media/md%d" % self.id) |
||||||
|
if (req.status_code == 200): |
||||||
|
tag = BeautifulSoup(req.text, 'lxml') |
||||||
|
script = tag.select("script")[3].text |
||||||
|
json_str = script[script.index("=") + 1:script.index("function") - 2] |
||||||
|
json_obj = json.loads(json_str) |
||||||
|
stat_info = json_obj['mediaInfo']['stat'] |
||||||
|
print(json_obj['mediaInfo']['chn_name']) |
||||||
|
print(stat_info) |
||||||
|
mediaInfo(id=self.id, chn_name=json_obj['mediaInfo']['chn_name']).save() |
||||||
|
global current_mediaInfo |
||||||
|
current_mediaInfo = mediaInfo.objects.get(pk=self.id) |
||||||
|
stat(id=self.id, danmakus=int(stat_info['danmakus']), favorites=stat_info['favorites'], |
||||||
|
views=stat_info['views']).save() |
||||||
|
|
||||||
|
def run(self) -> None: |
||||||
|
self.go(self.begin, self.end) |
||||||
|
|
||||||
|
def get(self): |
||||||
|
return current_mediaInfo |
||||||
|
|
||||||
|
def go(self, start, end): |
||||||
|
for num in range(start, end): |
||||||
|
if (flag): |
||||||
|
time.sleep(1) |
||||||
|
logger.info("爬虫进度:%d" % num) |
||||||
|
self.id = num |
||||||
|
self.save() |
||||||
|
else: |
||||||
|
logger.info("停止爬虫") |
||||||
|
break |
@ -0,0 +1,44 @@ |
|||||||
|
from django.db import models |
||||||
|
import json |
||||||
|
|
||||||
|
|
||||||
|
class param(models.Model): |
||||||
|
param_name = models.CharField(max_length=10, primary_key=True) |
||||||
|
param_value = models.CharField(max_length=128) |
||||||
|
|
||||||
|
|
||||||
|
class stat(models.Model): |
||||||
|
id = models.IntegerField(primary_key=True) |
||||||
|
danmakus = models.IntegerField() |
||||||
|
favorites = models.IntegerField() |
||||||
|
views = models.IntegerField() |
||||||
|
|
||||||
|
# def json(self): |
||||||
|
# return bangumi_stat(self['danmakus'],self['favorites'],self['views']) |
||||||
|
|
||||||
|
|
||||||
|
class mediaInfo(models.Model): |
||||||
|
id = models.IntegerField(primary_key=True) |
||||||
|
chn_name = models.CharField(max_length=128) |
||||||
|
|
||||||
|
def __str__(self) -> str: |
||||||
|
i = {} |
||||||
|
i['media_id'] = self.id |
||||||
|
i['chn_name'] = self.chn_name |
||||||
|
return i |
||||||
|
|
||||||
|
|
||||||
|
class bangumi_list(models.Model): |
||||||
|
season_id = models.IntegerField(primary_key=True) |
||||||
|
badge = models.CharField(max_length=128) |
||||||
|
brief = models.CharField(max_length=128) |
||||||
|
copyright = models.CharField(max_length=128) |
||||||
|
cover = models.CharField(max_length=128) |
||||||
|
favorites = models.IntegerField() |
||||||
|
is_finish = models.IntegerField() |
||||||
|
newest_ep_index = models.IntegerField() |
||||||
|
pub_time = models.DateTimeField() |
||||||
|
season_status = models.IntegerField() |
||||||
|
title = models.CharField(max_length=128) |
||||||
|
total_count = models.IntegerField() |
||||||
|
trailer_aid = models.IntegerField() |
@ -1,5 +0,0 @@ |
|||||||
from django.db import models |
|
||||||
|
|
||||||
class param(models.Model): |
|
||||||
param_name = models.CharField(max_length=10,primary_key=True) |
|
||||||
param_value = models.CharField(max_length=128) |
|
@ -0,0 +1,27 @@ |
|||||||
|
<html xmlns="http://www.w3.org/1999/html"> |
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<title>参数管理</title> |
||||||
|
{% load staticfiles %} |
||||||
|
<script src="{% static "js/jquery-3.2.1.min.js"%}"></script> |
||||||
|
<script> |
||||||
|
$(function () { |
||||||
|
$("button").click(function(){ |
||||||
|
$("form").attr("method",$(this).attr("id")).submit(); |
||||||
|
}); |
||||||
|
|
||||||
|
}) |
||||||
|
</script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<form action="/tsdm"> |
||||||
|
{% csrf_token %} |
||||||
|
<label>参数名<input name="param_name" value="{{param_name}}"/></label> |
||||||
|
<label>参数值<input name="param_value" value="{{param_value}}"/></label> |
||||||
|
<div> |
||||||
|
<button id="POST">设置</button> |
||||||
|
<button id="GET">获取</button> |
||||||
|
</div> |
||||||
|
</form> |
||||||
|
</body> |
||||||
|
</html> |
Loading…
Reference in new issue