1. 程式人生 > >bs4爬蟲處理解析html代碼,獲得屬性,獲取crsf認證,事件數據插入失敗回滾,# 局部禁用csrf認證,處理時間

bs4爬蟲處理解析html代碼,獲得屬性,獲取crsf認證,事件數據插入失敗回滾,# 局部禁用csrf認證,處理時間

爬蟲 annotate itl pro val time des strip() set

獲得屬性

var username = $(this).attr(‘username‘)
獲取crsf認證
token = $(‘[name=csrfmiddlewaretoken]‘).val()
data:{‘is_up‘:1,csrfmiddlewaretoken: token},
事件數據插入失敗回滾
from django.db import transaction
try:
with transaction.atomic():
except:
# 局部禁用csrf認證
from django.views.decorators.csrf import csrf_exempt, csrf_protect
處理時間
from django.db.models.functions import TruncMonth
time_list = user.blog.article_set.annotate(month=TruncMonth(‘create_time‘)).values(‘month‘).annotate(
c=Count(‘title‘))


# bs4爬蟲處理解析html代碼
from bs4 import BeautifulSoup
soup = BeautifulSoup(content, ‘html.parser‘)
desc = soup.text.strip()[0:100]
 

bs4爬蟲處理解析html代碼,獲得屬性,獲取crsf認證,事件數據插入失敗回滾,# 局部禁用csrf認證,處理時間