keys

Django-4

丶灬走出姿态 提交于 2019-12-03 16:28:11
看起来可能零散,但重在查漏补缺。 创建 utils 的 python 文件,专门用于存放我们自己写的公用的功能。 创建 forms 的 python 文件,专门用于校验。 已知 views 用于视图逻辑的实现、models 用于定义各种表结构 一、公共方法抽成公用的类 上次结尾讲到的对表的增删改查(四种请求方式),以及模糊查询、过滤、分页,这样的功能比较常见,所以抽成单独的类,使其具有普适性。 1 class Nbview(View): 2 search_field = [] 3 filter_field = [] 4 model = None 5 form_class = None 6 7 def get_filter_dict(self): 8 filter_dict = {} # 这个是用来过滤数据的字典 {'id':1,'name':'abc','phone':xxx} id=1,name=abc,phone=xxx 9 for field in self.filter_field: # 循环获取到有哪些过滤的字段 10 value = self.request.GET.get(field) 11 if value: 12 filter_dict[field] = value 13 return filter_dict 14 15 def get_search_obj

selenium学习-模拟键盘单个按键操作

两盒软妹~` 提交于 2019-12-03 14:34:04
导入 from selenium.webdriver.common.keys import Keys 格式:Keys.XXX 一般这么用:send_keys(Keys.XXX) 1 # coding=UTF-8 2 #18.模拟键盘单个按键操作 3 import sys 4 reload(sys) 5 sys.setdefaultencoding('utf8') 6 from selenium import webdriver 7 import unittest 8 import time 9 from selenium.webdriver.common.keys import Keys 10 11 class Case18(unittest.TestCase): 12 13 def setUp(self): 14 self.driver = webdriver.Chrome() 15 16 def test_simulateASingleKey(self): 17 url = "https://www.sogou.com" 18 self.driver.get(url) 19 element = self.driver.find_element_by_id("query") 20 element.send_keys(Keys.F12) # 按下F12键 21 time.sleep

Selenium XPath

孤街浪徒 提交于 2019-12-03 14:33:16
selenium 1、selenium是什么呢? selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法执行javaScript代码的问题。 它可以做什么呢?它可以用几行代码,控制浏览器,做出自动打开、输入、点击等操作,就像是有一个真正的用户在操作一样。 selenium允许让人去手动输入验证码,然后把剩下的操作交给机器。 而对于那些交互复杂、加密复杂的网站,selenium问题简化 ,爬动态网页如爬静态网页一样简单。 安装 pip install selenium # Windows电脑安装selenium selenium的脚本可以控制所有常见浏览器的操作,在使用之前,需要安装浏览器的驱动。 我推荐的是Chrome浏览器,打开下面的链接,就可以下载Chrome的安装包了,Windows和Mac都有。 国内镜像网站地址: http://npm.taobao.org/mirrors/chromedriver/2.38/ 设置浏览器引擎 下载chromed浏览器驱动: 把下载好的chromedriver.exe放到python安装路径的scripts目录中即可,注意最新版本是2.38,并非2.9 和以前一样,使用一个新的Python库,首先要调用它。selenium有点不同,除了调用,还需要设置浏览器引擎。 #本地Chrome浏览器设置方法

Travis-CI自动化测试并部署至自己的CentOS服务器

白昼怎懂夜的黑 提交于 2019-12-03 13:23:54
一直都想自己部署一下自动化测试部署,在了解了 Travis-CI 之后终于准备在这次和小伙伴一起做的一个博客类网站实验下了。 因为这是一个前后端分离的项目,所以我这里只管前端工程的自动化部署,前端主要用Vue脚手架搭建的单页应用。 环境准备 Github公开项目(Travis对 开源项目 是免费,对 私有项目 是收费的) Linux服务器(我这里用的腾讯云的学生机,系统是 CentOS 7.0 ) 终端连接器(我用的 SecureCRT ,自行下载安装,当然XShell等也可以,主要用于连接服务器操作) 自动化部署流程 本地修改代码,提交到指定分支 Travis监听仓库改变 Travis执行 install 和 script 任务(这里可以做一些安装测试构建任务的依赖和测试构建命令) 任务执行成功后,在Travis的 after_success 钩子里面用 ssh免密登陆 服务器 自动在服务器上执行配置的脚本 完成自动部署 Travis项目配置 一、创建Github仓库,初始化工程 在Github创建一个公有(public)仓库。在本地(我的Windows机器)上把仓库拉到本地来,在本地用 vue-cli 初始化vue单页应用(其实初始化单页应用对于这次操作不是必要的,因为我是vue工程,所以先新建一个,后面测试部署的时候方便一点。当然你也可以初始化一些其他的东西

Windows registry keys for applications for all users in machine

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I install an application on windows XP and that application writes some keys to HKCU registry , then will those keys be copied to HKCU for other users? I tried installing one application and verified some keys getting created in HKCU. Now I logged in into another user and I can find same keys in HKCU for that user. Both the users were in same Administrator group. I repeated the same steps in VMWare image of windows xp but I was not able to find the registry keys in other users in vmware image. I want to know that is it windows feature to

Typing Enter/Return key in Selenium

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for a quick way to type and Enter or Return key in Selenium. Unfortunately the form I'm trying to test (not my own code so I can't modify) doesn't have a Submit button. When working with it manually, I just type ENTER or RETURN . I need to know how to do that with the Selenium type command as there is no button to click. 回答1: import org.openqa.selenium.Keys WebElement.sendKeys(Keys.RETURN); the import statement is for Java, for other languages it is maybe a different, for example python: from selenium.webdriver.common.keys import

How to print all keys and values from MongoDB?

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have for instance following records in a collection: { "_id" : ObjectId("4f0224ad6f85ce027e000031"), "monday" : "7am" } { "_id" : ObjectId("4f0224ad6f85ce027e00002e"), "tuesday" : "11.40am" } { "_id" : ObjectId("4f0224ad6f85ce027e000025"), "wednestay" : "12am", "thursday" : "1pm" } In the controller I will grab all items and in the view I would like to print them in the shape: monday 7am tuesday 11.40am wednesday 12am thursday 1pm My app is running on Rails. Exist any quick & elegant way to do it? Thanks! EDIT this works me: records =

Hotkey to remap keys does not trigger hotstring

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a hotkey and hotstring that don't seem to work together: 9::( :?ob0:(::){left 1} To give some context, in one part of the code I remapped all the symbols to the number below them and vice versa so 9 prints the parenthesis ( . Later on I put a hotstring that would type a closed parenthesis after an open one and then places the cursor in between. Seems simple enough because they both work individually but together when I press the key for 9 and press the Spacebar I only get the open parenthesis ( as if the hotstring was ignored. Am I

Randomly Shuffle Keys and Values in Python DIctionary

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to randomly shuffle what keys correspond to what values? I have found random.sample but I was wondering if there was a more pythonic/faster way of doing this. Example: a = {"one":1,"two":2,"three":3} Shuffled: a_shuffled = {"one":2,"two":3,"three":1} 回答1: sorry the only way to make it faster is by using numpy :/. No matter what you do it has to somehow scramble all the indices which takes time - so doing it in C will help slightly. Also the difference between sheer random and this random is that you can't have repeated indices

Objective-C SBJSON: order of json array

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an iPhone application which gets a json string from a server and parses it. It contains some data and, eg. an array of comments. But I've noticed that the order of the json array is not preserved when I parse it like this: // parse response as json SBJSON * jsonParser = [ SBJSON new ]; NSDictionary * jsonData = [ jsonParser objectWithString : jsonResponse error : nil ]; NSDictionary * tmpDict = [ jsonData objectForKey :@ "rows" ]; NSLog (@ "keys coming!" ); NSArray * keys = [ tmpDict allKeys ]; for ( int i = 0 ; i < [ keys