首页
直播
壁纸
免责声明
更多
统计
关于
Search
1
一款自动化渗透工具包 TscanPlus
225 阅读
2
获取一张美国虚拟信用卡
223 阅读
3
JS Document.evaluate()的使用
199 阅读
4
Git冲突:Please commit your changes or stash them before you merge
176 阅读
5
Python 31条 pip 命令全解析
164 阅读
默认分类
操作系统
Linux
管理面板
实用工具
开发语言
PHP
Web
python
typecho
ThinkPHP
layui
爬虫
文章分享
登录
Search
标签搜索
python
php
web
linux
Git
js
requests
自动化
宝塔
thinkphp
Centos
adb
html
typecho
layui
jquery
ubuntu
multipass
虚拟机
thikphp
YiYun
累计撰写
54
篇文章
累计收到
21
条评论
首页
栏目
默认分类
操作系统
Linux
管理面板
实用工具
开发语言
PHP
Web
python
typecho
ThinkPHP
layui
爬虫
文章分享
页面
直播
壁纸
免责声明
统计
关于
搜索到
26
篇与
的结果
2024-03-28
requests 模块笔记
导入模块import requests请求方式: requests.get("https://www.baidu.com") requests.post("http://httpbin.org/post") requests.put("http://httpbin.org/put") requests.delete("http://httpbin.org/delete") requests.head("http://httpbin.org/get") requests.options("http://httpbin.org/get")获取数据: r = requests.get('http://www.baidu.com') #像目标url地址发送get请求,返回一个response对象 response.text返回的是Unicode格式,通常需要转换为utf-8格式。 response.content是二进制模式,可以下载视频之类的,如果想看的话需要decode成utf-8格式。 # response.content.decode("utf-8) 或 response.encoding="utf-8" 转码 print(r.text) # 返回响应的内容 print(r.content) # 这样获取的数据是二进制数据 print(r.url) # 打印请求网址的地址 print(r.status_code) # 打印请求页面的状态(状态码)# r.ok的布尔值便可以知道是否登陆成功 print(r.cookies) # 打印请求网址的cookies信息 print(r.headers) # 打印请求网址的headers所有信息 print(r.encoding) # 获取/修改网页编码 print(r.json()) # 返回json数据 print(r.history) # 打印请求的历史记录(以列表的形式显示)下载图片 response = requests.get("https://github.com/favicon.ico") with open('favicon.ico', 'wb') as f: f.write(response.content)例子:往请求链接中添加一些数据(data、headers、cookies、proxies...): import requests data = {'name': 'germey', 'age': '22'} cookie = {'key':'value'} headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'} proxies = {"http": "http://127.0.0.1:9743} requests.get(url='https://www.baidu.com/baidu', params={'wd': 'python',}) # 为url传递参数 https://www.baidu.com/baidu?wd=python response = requests.post( "https://www.zhihu.com/explore", data=data, # 如果传递的是string而不是dict,需要先调用dumps方法格式化一下 cookies=cookie, headers=headers, proxies=proxies) print (response.headers.get('content-type')) #访问响应头部分内容 补: requests.get(url, allow_redirects=False) # 不允许重定向,默认True # verify=False # 关闭证书验证其他操作会话维持cookie的一个作用就是可以用于模拟登陆,做会话维持 import requests session = requests.session() session.get('http://httpbin.org/cookies/set/number/12456') response = session.get('http://httpbin.org/cookies') print(response.text)代理设置 import requests proxies = { "http": "http://127.0.0.1:9743", # 设置普通代理 "https": "https://127.0.0.1:9743", # 设置普通代理 "http": "http://user:password@127.0.0.1:9743/", # 设置用户名和密码代理 } response = requests.get("https://www.taobao.com", proxies=proxies) print(response.status_code)设置socks代理安装socks模块 pip3 install 'requests[socks]' import requests proxies = { 'http': 'socks5://127.0.0.1:9742', 'https': 'socks5://127.0.0.1:9742' } response = requests.get("https://www.taobao.com", proxies=proxies) print(response.status_code)超时设置 import requests from requests.exceptions import ReadTimeout try: response = requests.get("http://httpbin.org/get", timeout = 0.5)#设置秒数超时,仅对于连接有效 print(response.status_code) except ReadTimeout: print('Timeout')获取cookie import requests response = requests.get("https://www.baidu.com") print(response.cookies) for key, value in response.cookies.items(): print(key + '=' + value)文件上传 import requests files = {'file': open('favicon.ico', 'rb')} response = requests.post("http://httpbin.org/post", files=files) print(response.text)认证设置 import requests from requests.auth import HTTPBasicAuth r = requests.get('http://120.27.34.24:9001', auth=HTTPBasicAuth('user', '123')) # r = requests.get('http://120.27.34.24:9001', auth=('user', '123')) print(r.status_code)关闭证书验证 import requests response = requests.get('https://www.12306.cn',verify=False) print(response.status_code)消除验证证书的警报 from requests.packages import urllib3 import requests urllib3.disable_warnings() response = requests.get('https://www.12306.cn',verify=False) print(response.status_code)手动设置证书 import requests response = requests.get('https://www.12306.cn', cert=('/path/server.crt', '/path/key')) print(response.status_code)异常处理 # RequestException继承IOError, # HTTPError,ConnectionError,Timeout继承RequestionException # ProxyError,SSLError继承ConnectionError # ReadTimeout继承Timeout异常 import requests from requests.exceptions import ReadTimeout, ConnectionError, RequestException try: response = requests.get("http://httpbin.org/get", timeout = 0.5) print(response.status_code) except ReadTimeout: print('Timeout') except ConnectionError: print('Connection error') except RequestException: print('Error') # RequestException # 发送一个模糊的异常 # ConnectionError # 发生连接错误时的异常 # HTTPError # 发生HTTP错误时的异常 # URLRequired # URL错误时的异常 # ConnectTimeout # 连接服务器是请求超时 # ReadTimeout # 服务器没有在指定的时间内发送数据 # Timeout # 请求超时原文出处: requests 模块笔记
2024年03月28日
69 阅读
0 评论
0 点赞
2024-03-28
JS之给元素添加类的方法
原生js中添加类的方法//1.为 <div> 元素添加一个类: document.getElementById("div").classList.add("类名"); //2.为 <div> 元素添加多个类: document.getElementById("div").classList.add("类名1","类名2","类名3",...); //3.为 <div> 元素移除一个类: document.getElementById("div").classList.remove("类名"); //4.为 <div> 元素移除多个类: document.getElementById("div").classList.remove("类名1","类名2","类名3",...); .jquery中添加类的方法//1.为 <div> 元素添加一个类: $("#div").addClass("类名"); //2.为 <div> 元素添加多个类: //只需要通过空格来间隔 class 值即可一次性添加多个 class $("#div").addClass("类名1 类名2 类名3"); //3.为 <div> 元素移除一个类: $("#div").removeClass("类名"); //4.为 <div> 元素移除多个类: //只需要通过空格来间隔 class 值即可一次性清除掉多个 class $("#div").removeClass("类名1 类名2 类名3"); 检查是否含有某个类的方法//检查是否含有某个CSS类 div.classList.contains('类名'); //return true or false
2024年03月28日
65 阅读
0 评论
0 点赞
2024-03-28
用tp6新建项目 -- 转载
用thinkphp6初始化一个项目composer安装tp6框架composer create-project topthink/think tp6tp6这个名字可以随意改动 添加多应用模式composer require topthink/think-multi-app添加视图,模板引擎composer require topthink/think-viewwin下phpstudy隐藏index.php文件,要在htaccess文件里/index.ph前面加个?添加权限类composer require zhenhaihou/think-auth原文出处:用tp6新建项目
2024年03月28日
130 阅读
0 评论
0 点赞
2024-03-28
layui 获取父页面的表格的值 -- 转载
如果您在 layui 中使用了表格组件,那么可以使用 layui 提供的 table 模块中的 getParentVal() 方法来获取父页面的表格的值。具体步骤如下:1.在父页面中定义表格,并给表格添加 id:<table id="parentTable"></table>2.在子页面中调用 getParentVal() 方法:var parentTable = parent.layui.table; // 获取父页面中的 table 模块 var parentTableData = parentTable.cache.parentTable; // 获取表格数据其中,parentTable 变量获取父页面中的 table 模块,parentTableData 变量获取父页面中表格的数据。注意,获取父页面中的 table 模块需要使用 parent 对象,该对象表示当前子页面所在的父页面。如果您需要获取表格中被选中的数据,则可以使用 layui 提供的 getCheckStatus() 方法来获取。示例代码如下:var parentTable = parent.layui.table; // 获取父页面中的 table 模块 var checkStatus = parentTable.checkStatus('parentTable'); // 获取选中行的数据 var checkedData = checkStatus.data; // 获取选中行的数据数组其中,checkStatus() 方法用于获取选中行的状态,'parentTable' 参数表示表格的 id,checkedData 变量则是选中行的数据数组。原文出处: layui 获取父页面的表格的值
2024年03月28日
75 阅读
0 评论
0 点赞
2024-03-27
thinkphp 命令行的使用--转载
1.前言ThinkPHP 支持 Console 应用,通过命令行的方式执行一些 URL 访问不方便或者安全性较高的操作。前面学习的接口封装,都是基于 HTTP 请求的,请求时间是会有超时时间的,若使用命令行可以在后台进程运行,而不是依赖于访问进程,ThinkPHP 命令行提供了一些方便的工具 ,下面介绍如何使用 ThinkPHP 命令行。2.通过命令行查看版本在框架的根目录下,有一个 think 脚本文件,可以使用 php 进程去调用它,查看 ThinkPHP 框架版本可以使用如下命令:php think version3.快速生成控制器若想要单应用 app\controller 目录下快速生成控制器和方法,可以使用如下命令:php think make:controller test生成的控制器文件内容如下:<?php declare (strict_types = 1); namespace app\controller; use think\Request; class test { /** * 显示资源列表 * * @return \think\Response */ public function index() { // } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { // } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ public function save(Request $request) { // } /** * 显示指定的资源 * * @param int $id * @return \think\Response */ public function read($id) { // } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update(Request $request, $id) { // } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete($id) { // } } {callout color="#002aff"}Tips: 其中快速生成几种常见的方法名,如果只想生成控制器可以使用 php think make:controller test --plain。{/callout}4.快速生成模型若想要单应用 app\model 目录下快速生成模型,可以使用如下命令:php think make:model TestModel生成的模型文件内容如下:<?php declare (strict_types = 1); namespace app\model; use think\Model; /** * @mixin \think\Model */ class TestModel extends Model { // }{callout color="#004cff"}Tips: declare (strict_types = 1)表示开启严格模式。{/callout}5.快速生成中间件若想要单应用 app\middleware 目录下快速生成模型,可以使用如下命令:php think make:middleware Auth生成的中间件文件内容如下:<?php declare (strict_types = 1); namespace app\middleware; class Auth { /** * 处理请求 * * @param \think\Request $request * @param \Closure $next * @return Response */ public function handle($request, \Closure $next) { // } }6.快速生成验证器若想要单应用 app\Models 目录下快速生成模型,可以使用如下命令:php think make:validate Test生成的验证器文件内容如下:<?php declare (strict_types = 1); namespace app\validate; use think\Validate; class Test extends Validate { /** * 定义验证规则 * 格式:'字段名' => ['规则1','规则2'...] * * @var array */ protected $rule = []; /** * 定义错误信息 * 格式:'字段名.规则名' => '错误信息' * * @var array */ protected $message = []; } 7.清除缓存文件若想要清除 runtime目录下的缓存文件,可以使用如下命令:php think clear清除之后如下图所示:{callout color="#004cff"}Tips: 若不需要保留空目录,可以使用 php think clear --dir。{/callout}8.输出路由定义列表若想要查看定义了哪些路由,可以使用如下命令:php think route:list9.小结本小节介绍了如何简单的使用 ThinkPHP 提供的命令行,使用这些命令行可以快速的生成控制器、模型、中间件、验证器,也可以根据实际情况选择手动创建这些文件,另外还介绍了如何使用命令行清空缓存,使用命令行查看框架中定义了哪些路由的列表。熟练地掌握这些命令行将会使你的开发效率更高。原文链接:https://www.imooc.com/wiki/thinkphplesson/thinkcommand.html
2024年03月27日
141 阅读
0 评论
0 点赞
1
...
4
5
6