CH0101 a^b 【快速冪的兩類理解】
Django(建表,配置一些的就不說了):
class Jiayou(models.Model): # 建表以及欄位名
zxn_title = models.CharField(max_length=500)
zxn_brief = models.CharField(max_length=500)
zxn_date = models.CharField(max_length=500)
zxn_position = models.CharField(max_length=500)
zxn_category = models.CharField(max_length=500)
zxn_cnum = models.CharField(max_length=500)
class Meta:
db_table = 'Jiayou' # 表名
Django(views get請求程式碼):
class JiayouView(APIView):
def get(self, request):
zxn = models.Jiayou.objects.all() # 獲取表裡所有資料
data = JiayouSerializer(zxn, many=True) # 用序列化新增資料
return Response({ # 返回響應
"status": 200,
"msg": "",
"data": data.data
})
爬蟲scrapy框架(程式碼):
class KaoshiSpider(scrapy.Spider):
name = 'kaoshi'
start_urls = ['
# print(start_urls) def parse(self, response): set = response.xpath('.//div[@class="list bgb "]/ul/li') for list in set: zxn_title = list.xpath('./h2/a/text()').extract()[0] # print(zxn_title) zxn_brief = ''.join(list.xpath('./p/text()').extract()) # print(zxn_brief) zxn_date = ''.join(list.xpath('./small/span[1]/text()').extract()).replace('\r', '').replace('\n', '').replace('勵志人生網', '') # print(zxn_date) zxn_position = ''.join(list.xpath('./small/span[2]/text()').extract()).replace('\r', '').replace('\n', '') # print(zxn_position) zxn_category = ''.join(list.xpath('./small/span[3]/a/text()').extract()).replace('\r', '').replace('\n','').replace('勵志人生網', '') print(zxn_category) zxn_cnum = ''.join(list.xpath('./small/span[4]/text()').extract()).replace('\r', '').replace('\n','').replace('勵志人生網', '') # print(category) yield YuekaoItem(zxn_title=zxn_title,zxn_brief=zxn_brief,zxn_date=zxn_date,zxn_position=zxn_position,zxn_category=zxn_category,zxn_cnum=zxn_cnum)
vue(程式碼 我使用前端跨域展示)
id
zxn_title
zxn_brief
zxn_date
zxn_position
zxn_category
zxn_cnum
{{i.id}}
{{i.zxn_title}}
{{i.zxn_brief }}
{{i.zxn_date}}
{{i.zxn_position}}
{{i.zxn_category}}
{{i.zxn_cnum}}