試驗form的POST之前,先將django的CSRF注釋掉。
再放爬蟲來訪問網頁,測試網站穩定性。
import json, requests, sys
from bs4 import BeautifulSoup
# 打開網頁,判斷為靜態網頁
def scrapy_get():
url ='http://127.0.0.1:8000'
response = requests.get(url)
print(response.status_code)
scrapy_get()
# # 爬取數據 並保存數據
# pageSource = response.text # 獲取Elements中渲染完成的網頁源代碼
# soup = BeautifulSoup(pageSource,'html.parser') # 使用bs解析網頁
# print(soup)
def scrapy_post():
url ='http://127.0.0.1:8000'
# data={'sitedata': '---','statusdata':'1-todo',}
data={
'username': '****','password':'****','statusdata':'1-todo',}
response = requests.post(url,data=data)
print(response.status_code)
pageSource = response.text # 獲取Elements中渲染完成的網頁源代碼
soup = BeautifulSoup(pageSource,'html.parser') # 使用bs解析網頁
print(soup)
for i in range(100):
scrapy_post()