輪播組件/瀑布流/組合搜索/KindEditor插件

1、企業官網

### 瀑布流html

​ Models.Student.objects.all() #獲取全部學員信息前端

​ 經過div進行循環圖片和字幕python

​ 1.以template模板方法實現瀑布流以列爲單位放置圖片和字母信息:經過取餘的方式分列,三列就對三取餘,在templatetags裏面自定義模板,可是對於前端建立的判斷方法if,時不能使用@register.simple_tag,simple_tag方法不能用於if 後,因此引用filter方法:@register.filterweb

​ 2.以JS的方式實現瀑布流以列爲單位放置圖片和字母信息:經過JS進行求餘運算實現瀑布流django

輪播圖:

輪播圖bxlider插件:依賴於Jqueryjson

組合搜索

​ 目的是信息的查詢過濾後端

​ models.Video.objects.filter() # 查詢:使用字典進行組合查詢,在前端經過類型id實現動態組合索引,最簡單的組合查詢方法,數據類型無關聯瀏覽器

示例:sparta(學習示例,非本人所寫,就不發連接了)服務器

​ 安裝python2.7微信

​ pip2 install django==1.7.8

​ pip2 install Pillow

2、博客系統

​ 我的博客註冊

​ 我的主頁

​ 我的後臺管理

​ 主題定製

​ Editor(回存在XSS攻擊)

​ TinyEditor(IE的)

​ UEEditor (百度的)

​ CKEditor(比較老的)

​ KindEditor(中文版的)

​ KindEditor:

​ 基本配置

​ 處理XSS

​ Beautifulsoup4模塊使用

3、Tornado

​ Web框架:Tornado

​ Tornado內置模塊實現爬蟲

4、爬蟲

​ requests模塊:請求地址獲取文件,模擬瀏覽器向服務端發送請求

  • requests.put()

  • requests.get()

  • requests.post()

  • requests.patch()

  • requests.delete()

  • requests.head()

  • requests.options()

  • requests.request()

  • allow_redirects參數,是不是否重定向

    # Author:wylkjj
    # Date:2020/2/23
    # -*- coding:utf-8 -*-
    import requests
    from bs4 import BeautifulSoup
    import json
    
    # requests發送get請求
    response = requests.get('https://www.bilibili.com/')
    # print(response.text)
    soup = BeautifulSoup(response.text, features="html.parser")
    text_list = soup.find_all(name='div', class_='item')
    print(text_list)
    
    
    # requests發送post請求
    form_data = {
        'phone': '+8615044487970',
        'password': 'adpsasfff',
        'loginType': 2,
    }
    
    # request 參數 
    response = requests.post(
        url='https://dig.chouti.com/login',
        data=form_data,    # 請求頭爲 content-type:application/x-www-form-urlencoded
        params={'eric': '123456'},  # 拼接後url http://www.baidu.com/?query=eric
        json=json.dumps({'user': 'eric', 'pwd': '12345'}),  # 請求頭會改變content-type:application/json
    )
    print(response.text)
    
    # request 參數 
    requests.request(
        method = "GET",
        url = "http://www.baidu.com",
        params = {'query':'eric'},  
        data={},  # 數據傳輸,get用不到,post時把data數據放到請求體中傳輸到後端
        header={
            'referer': 'https://www.zhihu.com/signin?next=http%3A%2F%2Fwww.zhihu.com%2Fpeople%2Feric-wijing',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3970.5 Safari/537.36'
        },  # 當requests訪問被拒絕時,設置header中的Referer或'user-agent',由於多是他們兩個參數的問題,在network發送請求後的Header中
        cookies={},  
    )  
    
    # request 參數 
    response = requests.get(
        url='https://i-beta.cnblogs.com/settings',
        # 獲取已登錄的信息
        cookies={'.CNBlogsCookie':'93C26874509F65701B9F02163426CC74B23CDE7B9383331E04AEA2BEA2FEBEB0E3DA7F41FAF308FB36B946F007B8981D38AFE66E2042A6A80D2E5BF31E45BCECF0A3343E9AA83FDDCC155278666854E135E069A3',},
        cert:'證書文件'  # 有些網站須要證書才能獲取數據
    )
    print(response.text)

​ beautifulsoup:數據區提取(格式化)

​ 使用方法:引入from bs4 import BeautifulSoup,建立對象:soup = BeautifulSoup(html_doc, features="html.parser"),html_doc是要解析的對象,features="html.parser"是解析器,最快的解析器是lxml解析器,不過須要自行安裝,html解析器是python內置的解析器;

​ soup.children的方法是獲取全部模塊,只不過只會尋找第一層body ;

​ soup.body.children會尋找出body全部的元素(body的下一層);

​ for tag in soup.body.descendants:循環tag.name能獲取標籤的類型屬性(有div,就會得到其屬性div),單獨輸出tag,循環遍歷出全部標籤;

​ from bs4 import Tag:遍歷的每個標籤,獲取其屬性,可用其判斷獲取全部元素的屬性;循環tag.name能獲取詳細的標籤類型屬性(有div,就會得到其屬性div);tag.attrs能夠獲取全部的標籤內部的全部屬性對其進行增刪改查操做。

​ soup.html.hidden = True;soup.head.hidden = True ;顯示出隱藏的標籤,若是不設置此屬性,在進行soup操做時不會讀取出hidden隱藏的內容。

# Author:wylkjj
# Date:2020/2/23
from bs4 import BeautifulSoup
from bs4 import Tag
# Create your views here.
html_doc = """
<body>
<div class="bili-banner1" style="background-image: url(&quot;//i0.hdslb.com/bfs/archive/7197cae46569a49abd98e0c51348068831be6a85.png&quot;);" data-v-5ff46558=""><div class="taper-line" data-v-5ff46558=""></div><div class="b-logo b-wrap" style="margin: 0" data-v-5ff46558=""><a href="//www.bilibili.com" class="head-logo" data-v-5ff46558=""><img src="//i0.hdslb.com/bfs/archive/1be2fd76cc98cdc6a595c05c3134fbf937a1c126.png" class="logo-img" data-v-5ff46558="">123456789</a><!----></div><!----></div>
<div class="bili-banner2" style="background-image: url(&quot;//i0.hdslb.com/bfs/archive/7197cae46569a49abd98e0c51348068831be6a85.png&quot;);" data-v-5ff46558=""><div class="taper-line" data-v-5ff46558=""></div><div class="b-logo b-wrap" style="margin: 0" data-v-5ff46558=""><a href="//www.bilibili.com" class="head-logo" data-v-5ff46558=""><img src="//i0.hdslb.com/bfs/archive/1be2fd76cc98cdc6a595c05c3134fbf937a1c126.png" class="logo-img" data-v-5ff46558="">123456789</a><!----></div><!----></div>
asdfasfasdfasdf
<a>123456</a>
<h3>123456</h3>
<div class="bili-banner3" style="background-image: url(&quot;//i0.hdslb.com/bfs/archive/7197cae46569a49abd98e0c51348068831be6a85.png&quot;);" data-v-5ff46558=""><div class="taper-line" data-v-5ff46558=""></div><div class="b-logo b-wrap" style="margin: 0" data-v-5ff46558=""><a href="//www.bilibili.com" class="head-logo" data-v-5ff46558=""><img src="//i0.hdslb.com/bfs/archive/1be2fd76cc98cdc6a595c05c3134fbf937a1c126.png" class="logo-img" data-v-5ff46558="">123456789</a><!----></div><!----></div>
</body>
"""
# python內置解析器,但lxml使用時解析最快,須要安裝
soup = BeautifulSoup(html_doc, features="html.parser")
# tag1 = soup.find(name='a')
for tag in soup.body.descendants:
# for tag in soup.body.children:
# for tag in soup.children:
    if isinstance(tag, Tag):
        # print("屬性:", tag.name, tag.attrs)
        pass
tag1 = soup.find(name='a')
del tag1.attrs['class']
print(tag1)
print(soup)

tag1 = soup.find(name='a')
tag1.clear()
print(tag1)
print(soup)

​ 單例模式:使用一個對象進行操做

# Author:wylkjj
# Date:2020/2/23
# -*- coding:utf-8 -*-

# 建立單例模式第一種方法
class Foo:
    __instance = None

    @classmethod
    def instance(cls):
        if Foo.__instance:
            return Foo.__instance
        else:
            obj = Foo()
            Foo.__instance = obj
            return Foo.__instance


obj1 = Foo()
obj2 = Foo()
print(obj1, obj2)


# 建立單例模式第二種方法
class Fo(object):
    __instance = None

    def __init__(self):
        pass

    def __new__(cls, *args, **kwargs):
        if cls.__instance:
            return cls.__instance
        else:
            obj = object.__new__(cls, *args, **kwargs)  # 建立類
            cls.__instance = obj
            return cls.__instance


obj3 = Fo()
obj4 = Fo()
print(obj3, obj4)

​ scrapy框架:爬蟲框架

5、Web微信/微信公衆平臺登陸

只是在網頁端容許登陸時可使用,可是因爲微信取消了網頁端的登陸,沒法實現,純屬我的喜愛,理解理解。

輪詢:

  客戶端定時向服務器端發送 Ajax 請求,服務器端接收到請求後立刻返回信息並關閉鏈接。缺點是:有延時,沒法知足即時通訊的需求。

長輪詢(Comet):

  客戶端向服務器端發送 Ajax 請求,服務器端接收到請求後保持住鏈接,直到有新消息才返回響應信息並關閉鏈接。客戶端在處理請求返回信息(超時或有效數據)後再次發出請求,從新創建鏈接。缺點是:服務器保持鏈接會消耗較多的資源。

WEB微信頁:

  • 訪問頁面出現二維碼
  • 長輪詢監聽是否已經掃碼而且點擊確認
  • 如何進行會話保持
  • 如何獲取用戶列表
  • 如何發送消息(接受消息)

微信二維碼獲取地址的前綴:https://login.weixin.qq.com/qrcode/{0}

因爲如今沒法進行操做,其它內容就不編輯了

相關文章
相關標籤/搜索