2023-5-25 myluzh
程序开发
是否可以使用 Chrome Headless 设置自定义位置坐标?我在里面找不到。
Is it possible to set custom location coordinates with Chrome Headless? I can't find it in the Devtools protocol API. Is there a workaround available?
解决方案
I googled it and got many methods. I try one by one, almost all of them turn out outdated. Then I find out a solution, use chrome devtools protocol to achieve that.
The small example code below, that it uses the most common tool selenium to execute chrome devtools protocol command.
import time
...
阅读全文>>
标签: selenium Chrome 传感器 位置 虚拟定位
评论(0)
(63)
2023-5-24 myluzh
程序开发
0x01 原始的Form表单
用户提交数据没有校验。
页面上没有错误提示。
页面上每个字段都要写一遍。
关联的数据还需要手动获取后循环展示在页面中。
0x02 Django组件-Form
views.py
from django.forms import Form
class MyForm(Form):
user = forms.CharField(widget=forms.Input)
pwd = form.CharFiled(widget=forms.Input)
email = form.CharFiled(widget=forms.Input)
def user_add(request):
if request.method == "GET":
form = MyForm()
return render(request, 'user_add.html', {"form": form})
user_add.html
<form method="post">
...
阅读全文>>
标签: django
评论(0)
(53)
2023-5-23 myluzh
程序开发
import requests
# 设置代理,多用于爬虫
proxies = {"http":"http://12.34.56.79:9527",
"https":"https://12.34.56.79:9527"}
# 1.普通的代理
rqq= requests.get(url="http://www.baidu.com",proxies=proxies)
print(res.content.decode("utf-8"))
# 2.携带了登录的用户名和密码
# proxies1 = {"http":"http://用户名:密码@12.34.56.79:9527"}
# rqq = requests.get(url="http://www.baidu.com",proxies=proxies1)
阅读全文>>
标签: python requests
评论(0)
(16)
2023-5-20 myluzh
程序开发
0x01 前言
Django操作数据库更简单,因为内部提供了ORM框架。ORM依赖于第三方模块,需要pip进行安装。
pip3 install mysqlclient
ORM可以帮助我们创建、修改、删除数据库中的表(不用写sql语句,无法创建数据库),操作表里面的数据。
如何使用自带工具创建数据库?使用mysql -u root -p 进入mysql后,运行如下命令创建一个DjangoDB的数据库。
create database django DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
0x02 Django链接数据库
1.修改setting.py DATABASES文件,把直接的sqllite配置改成mysql的连接配置。如下:
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql', # 默认
'NAME': 'django', # 连接的数据库名称
...
阅读全文>>
标签: django
评论(0)
(44)
2023-5-20 myluzh
程序开发
0x01 请求和响应的方式
def something(request):
# 关于request:是一个对象封装了用户发送过来的所有请求数据
# 获取用户请求方式,GET/POST
print(request.method)
# 获取GET参数
print(request.GET)
# 获取POST参数
print(request.POST)
# 获取GET中的a参数
print(request.GET['a'])
# 响应方式1.通过render方式,通过html模板输出
return render(request,"something.html")
# 响应方式2.通过HttpResponse方式,直接返回内容
return HttpResponse(request.GET['a'])
# 响应方式3.通过redirect方式,重定向链接
return redirect("https://www.baidu.com")
...
阅读全文>>
标签: djiango
评论(0)
(23)
2023-5-20 myluzh
程序开发
制定一个模板文件 layout.html 模板文件内容如下:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'plugins/bootstrap-3.4.1/css/bootstrap.min.css' %}">
</head>
<body>
<!-- 导航条内容 -->
<nav class="navbar navbar-default"></nav>
<!-- 主体部分使用{% block content%}{% endblock %}-->
<div class="contain...
阅读全文>>
标签: django
评论(0)
(24)