02 2024 档案

摘要:Request ——http请求中的东西,都能从request中取出来 # 请求相关信息 request.method # 提交的方法 request.args # get请求提及的数据 request.form # post请求提交的数据 request.values # post和get提交的数 阅读全文
posted @ 2024-02-29 16:33 wellplayed 阅读(11) 评论(0) 推荐(0) 编辑
摘要:FBV写法 from flask import Flask, jsonify app = Flask(__name__) app.debug = True @app.route('/') def index(): return 'hello' CBV写法 # 导入模块 from flask.view 阅读全文
posted @ 2024-02-29 15:40 wellplayed 阅读(7) 评论(0) 推荐(0) 编辑
摘要:配置文件预览 DEFAULT_CONVERTERS = { 'default': UnicodeConverter, 'string': UnicodeConverter, 'any': AnyConverter, 'path': PathConverter, 'int': IntegerConve 阅读全文
posted @ 2024-02-29 15:26 wellplayed 阅读(13) 评论(0) 推荐(1) 编辑
摘要:前置代码 from flask import Flask, jsonify app = Flask(__name__) 1 flask 路由系统是基于装饰器的,但是它的本质是: add_url_rule 2 装饰器的参数及作用 ''' 1 rule : 路径 2 methods: 可以允许的请求方式 阅读全文
posted @ 2024-02-28 16:55 wellplayed 阅读(14) 评论(0) 推荐(1) 编辑
摘要:flask的几种配置文件方式 方式一:放在app对象上,本质会放在 app.config 里面 app.secret_key = 'asdfsdf' app.debug = False 方式二:放在app对象的config参数上 app.config['DEBUG'] = True app.conf 阅读全文
posted @ 2024-02-28 16:35 wellplayed 阅读(156) 评论(0) 推荐(0) 编辑
摘要:一 装饰器,需要放在路由装饰器下面 ''' 在执行视图函数之前,做判断--》 路由的装饰器是控制路由匹配的--》 需要先执行,所以登录认证装饰器,需要放在下面 ''' 二 需要直接指定路由别名 原因 ''' 直接添加会报错————每个路由,都会有个别名,如果不写,默认以函数名作为别名 如果视图函数加 阅读全文
posted @ 2024-02-28 16:03 wellplayed 阅读(33) 评论(0) 推荐(0) 编辑
摘要:新手四件套(返回格式) # 导入 from flask import Flask, request, render_template, redirect, session # 返回字符串 return '字符串' # 返回模板 return render_template('模板名字') # 传参 阅读全文
posted @ 2024-02-28 15:51 wellplayed 阅读(13) 评论(0) 推荐(1) 编辑
摘要:开启debug模式的作用 1 浏览器显示错误信息 2 修改代码会自动重启 开启方式 flask --app 文件名.py run --debug # 书写代码开启方式 app = Flask(__name__) app.debug = True 阅读全文
posted @ 2024-02-27 17:08 wellplayed 阅读(142) 评论(0) 推荐(0) 编辑
摘要:方式一(pycharm配置) 首先新建一个flask-server 目标文件选择需要运行的文件地址即可 方式二:命令运行(推荐这种) flask --app 文件名字.py run # 或者 python3 -m flask --app 文件名字.py run 方式三:右键运行 # 必要代码 if 阅读全文
posted @ 2024-02-27 17:04 wellplayed 阅读(711) 评论(0) 推荐(0) 编辑
摘要:Mac/linux # 创建虚拟环境 mkdir myproject cd myproject python3 -m venv .venv # 激活虚拟环境 . .venv/bin/activate Win # 创建虚拟环境 mkdir myproject cd myproject py -3 -m 阅读全文
posted @ 2024-02-27 16:53 wellplayed 阅读(16) 评论(0) 推荐(0) 编辑
摘要:安装模块 pip3 install python-dotenv 使用方式 需要在根路径下新建 .env 文件,并写入配置 import os from dotenv import load_dotenv from dotenv import dotenv_values ### 方法一 res=loa 阅读全文
posted @ 2024-02-27 16:49 wellplayed 阅读(698) 评论(0) 推荐(0) 编辑
摘要:功能 当前目录下文件修改会被监控到,并打印日志 安装模块 pip3 install watchdog 运行方式 ——运行文件即可开启监控,自动监测文件变化 import sys import time import logging from watchdog.observers import Obs 阅读全文
posted @ 2024-02-27 15:57 wellplayed 阅读(38) 评论(0) 推荐(1) 编辑
摘要:介绍 Click 是一个 Python 包,用于以可组合的方式使用尽可能少的代码创建漂亮的【命令行界面】。它是“命令行界面创建工具包”。它具有高度可配置性,但具有开箱即用的合理默认值 它的目的是使编写命令行工具的过程变得快速而有趣,同时也防止因无法实现预期的 CLI API 而造成的任何挫败感 Cl 阅读全文
posted @ 2024-02-27 15:52 wellplayed 阅读(10) 评论(0) 推荐(1) 编辑
摘要:安装模块 pip intall flask 运行 from flask import Flask app = Flask(__name__) # 访问根路径打印字符串 @app.route('/') def index(): return 'hello world' if __name__ == ' 阅读全文
posted @ 2024-02-27 14:48 wellplayed 阅读(8) 评论(0) 推荐(0) 编辑
摘要:配置文件结构 #### 基础配置 # 项目名 BOT_NAME = "scrapy_demo" # 爬虫所在路径 SPIDER_MODULES = ["scrapy_demo.spiders"] NEWSPIDER_MODULE = "scrapy_demo.spiders" # 日志级别 LOG_ 阅读全文
posted @ 2024-02-23 16:20 wellplayed 阅读(16) 评论(0) 推荐(0) 编辑
摘要:scrapy目录结构 myfirstscrapy # 项目名字 -myfirstscrapy # 包 -__init__.py -spiders # 包 放爬虫,可能会有很多爬虫 -__init__.py -cnblogs.py # 爬虫文件--》一个爬虫就是一个文件,可以写多个 -items.py 阅读全文
posted @ 2024-02-23 16:04 wellplayed 阅读(26) 评论(0) 推荐(0) 编辑
摘要:校验密码 from django.contrib.auth.hashers import check_password # 需要导入User表 from django.contrib.auth.models import User # 实例化得到user对象 user = User.object.f 阅读全文
posted @ 2024-02-22 16:14 wellplayed 阅读(110) 评论(0) 推荐(0) 编辑
摘要:第一步:安装scrapy模块 pip install scrapy 第二步:在需要创建的文件夹内打开cmd窗口输入 scrapy startproject myfirstscrapy 会看到下面的命令: You can start your first spider with: cd myfirst 阅读全文
posted @ 2024-02-22 15:39 wellplayed 阅读(29) 评论(0) 推荐(0) 编辑
摘要:三种实现拖拽功能的方式 from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.support.wait import WebDriverWait # 等待页 阅读全文
posted @ 2024-02-22 15:09 wellplayed 阅读(11) 评论(0) 推荐(0) 编辑
摘要:语法格式如下 1 标签名 # 找xml中所有这个标签 2 / # 只找一层 3 // # 子子孙孙都会找 4 . # 从当前路径下 5 .. # 上一层 6 @属性名 # 找有这个属性的标签 数据准备 doc=''' <html> <head> <base href='http://example. 阅读全文
posted @ 2024-02-22 15:00 wellplayed 阅读(28) 评论(0) 推荐(0) 编辑
摘要:自动登陆获取cookies: import json import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.edge.service 阅读全文
posted @ 2024-02-21 16:20 wellplayed 阅读(16) 评论(0) 推荐(0) 编辑
摘要:执行js 前置准备 import time from selenium import webdriver from selenium.webdriver.edge.service import Service ser = Service() ser.path = r'D:\xxx\chromedri 阅读全文
posted @ 2024-02-21 16:18 wellplayed 阅读(26) 评论(0) 推荐(0) 编辑
摘要:使用场景: 如果我们只需要获取执行后的数据结果,而不需要打开浏览器,就用得上无头浏览器 设置方式: 额外添加以下代码: from selenium.webdriver.chrome.options import Options options = Options() options.add_argu 阅读全文
posted @ 2024-02-21 15:47 wellplayed 阅读(160) 评论(0) 推荐(0) 编辑
摘要:存在的问题: 我们在find_element找标签时候,标签有可能还没加载出来。而代码执行非常快,这时候取不到标签就会报错,只需加入以下一行代码: bro.implicitly_wait(10) ''' 加了这一句代码,当咱们取标签的时候,如果标签没加载好,最多等待10s,一旦标签加载出来后就会继续 阅读全文
posted @ 2024-02-21 15:42 wellplayed 阅读(6) 评论(0) 推荐(0) 编辑
摘要:搜索标签 1 By.ID # 根据id号查找标签 bro.find_element(By.ID, 'id内容') 2 By.NAME # 根据name属性查找标签 3 By.TAG_NAME # 根据标签名查找标签 a_list=bro.find_elements(By.TAG_NAME,'a') 阅读全文
posted @ 2024-02-21 15:36 wellplayed 阅读(306) 评论(0) 推荐(0) 编辑
摘要:selenium介绍 selenium本质是通过驱动浏览器,完全模拟浏览器的操作,比如跳转、输入、点击、下拉等,来拿到网页渲染之后的结果,可支持多种浏览器 快速使用 第一步:确认要驱动的浏览器(以谷歌浏览器为例) 第二步:下载与浏览器版本对应的驱动 https://googlechromelabs. 阅读全文
posted @ 2024-02-21 15:16 wellplayed 阅读(10) 评论(0) 推荐(0) 编辑
摘要:数据准备 html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p id="my_p" class="title"><b id="bbb" class="boldest">The Dormouse' 阅读全文
posted @ 2024-02-20 16:35 wellplayed 阅读(16) 评论(0) 推荐(0) 编辑
摘要:数据准备: # 导入模块 from bs4 import BeautifulSoup # 查询数据文本 html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title" id=' 阅读全文
posted @ 2024-02-20 16:30 wellplayed 阅读(9) 评论(0) 推荐(0) 编辑
摘要:数据准备: # 导入模块 from bs4 import BeautifulSoup # 查询数据文本 html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title" id=' 阅读全文
posted @ 2024-02-20 16:09 wellplayed 阅读(11) 评论(0) 推荐(0) 编辑
摘要:第一步:安装 pip install pymysql 第二步:使用方式 # 导入模块 import pymysql # 建立连接 conn = pymysql.connect( user='root', password="root", host='127.0.0.1', database='car 阅读全文
posted @ 2024-02-20 15:48 wellplayed 阅读(14) 评论(0) 推荐(0) 编辑
摘要:搭建并使用代理的步骤 1 搭建免费代理池 项目下载地址:https://github.com/jhao104/proxy_pool 2 使用虚拟环境安装依赖 3 修改配置文件中的redis配置 DB_CONN = 'redis://127.0.0.1:6379/2' 4 启动爬虫获取免费代理并存入r 阅读全文
posted @ 2024-02-20 15:14 wellplayed 阅读(40) 评论(0) 推荐(0) 编辑
摘要:http 和 https区别 -http:超文本传输协议 -https:安全的超文本传输协议 -https=http+ssl/tls -防止:篡改,截取 -必须有证书:才能通信 使用方式 import requests header = { 'User-Agent': 'Mozilla/5.0 (W 阅读全文
posted @ 2024-02-19 16:33 wellplayed 阅读(206) 评论(0) 推荐(0) 编辑
摘要:获取代理池ip import requests res = requests.get('http://demo.spiderpy.cn/get/?type=https') print(res.json()) print(res.json()['proxy']) # 112.30.155.83:127 阅读全文
posted @ 2024-02-19 16:31 wellplayed 阅读(81) 评论(0) 推荐(0) 编辑
摘要:超时设置 import requests respone=requests.get('https://www.baidu.com',timeout=0.0001) 异常处理 import requests from requests.exceptions import * #可以查看requests 阅读全文
posted @ 2024-02-19 16:28 wellplayed 阅读(19) 评论(0) 推荐(0) 编辑
摘要:requests发送请求后会返回响应对象 import requests respone = requests.get('xxx') respone属性 响应体--字符串形式 print(respone.text) 响应体--bytes格式 print(respone.content) 响应状态码 阅读全文
posted @ 2024-02-19 16:17 wellplayed 阅读(15) 评论(0) 推荐(0) 编辑
摘要:发送登录请求 import requests data = { 'username': '用户名', 'password': '密码', 'captcha': '3333', 'remember': '1', 'ref': ' http://www.aa7a.cn/', # 登录成功,重定向到这个地 阅读全文
posted @ 2024-02-19 16:03 wellplayed 阅读(101) 评论(0) 推荐(0) 编辑
摘要:首先需要导入模块 import requests 携带get请求方式 params = { 'xxx': 'yyy', } res = requests.get('xxx',params=params) print(res.text) # 打印响应体内容 携带请求头 headers = { 'Use 阅读全文
posted @ 2024-02-19 15:49 wellplayed 阅读(10) 评论(0) 推荐(0) 编辑
摘要:自定义库存表(Stock) class Stock(models.Model): amount = amount = models.IntegerField(verbose_name='数量') price = models.DecimalField(max_digits=10, decimal_p 阅读全文
posted @ 2024-02-15 20:14 wellplayed 阅读(18) 评论(0) 推荐(0) 编辑
摘要:第一步:组件后面加上v-if方法 <div id="app" ref="app"> <router-view v-if="is_show"/> </div> 第二步:data定义一个变量控制v-if data() { return { is_show: true //定义一个变量控制v-if } 第 阅读全文
posted @ 2024-02-07 23:30 wellplayed 阅读(898) 评论(0) 推荐(0) 编辑
摘要:第一步:安装echarts模块 cnpm install echarts -S 第二步:在 main.js中全局引入 import echarts from 'echarts' Vue.prototype.$echarts = echarts // 全局引入 后面用this.$echarts就能直接 阅读全文
posted @ 2024-02-07 23:21 wellplayed 阅读(19) 评论(0) 推荐(0) 编辑
摘要:Windows系统 修改package.json文件: "scripts": { "serve": "set NODE_OPTIONS openssl-legacy-provider && vue-cli-service serve", "build": "set NODE_OPTIONS open 阅读全文
posted @ 2024-02-03 16:41 wellplayed 阅读(46) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示