Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

seozed seozed

🌴
On vacation
Block or report user

Report or block seozed

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@seozed
seozed / mongo.js
Last active May 21, 2020
mongo 统计字段的长度并汇总
View mongo.js
db.getCollection("mastersportal_counrse").aggregate([
{
"$project": {
"overview": {
"$strLenCP": "$overview"
},
"about": {
"$strLenCP": "$about"
}
@seozed
seozed / crate_decorator.py
Created May 21, 2020
快速声明一个装饰器
View crate_decorator.py
from functools import wraps
def timethis(func):
'''
Create a decorator .
'''
@wraps(func)
def wrapper(*args, **kwargs):
@seozed
seozed / 遍历子控件.js
Last active May 20, 2020
[example-for-autojs] #autojs
View 遍历子控件.js
var list = className("AbsListView").findOne();
for(var i = 0; i < list.childCount(); i++){
var child = list.child(i);
log(child.className());
}
@seozed
seozed / click_by_bounds.js
Created May 20, 2020
[click_by_bounds] #autojs
View click_by_bounds.js
/** 通过元素的坐标进行点击事件
*
* @param {*} selector 元素选择器
*/
function click_by_bounds(selector){
var b = selector.findOne().bounds();
return click(b.centerX(), b.centerY());
}
@seozed
seozed / snippet in scrapy.py
Last active May 20, 2020
[提升scrapy编码效率的片段]
View snippet in scrapy.py
from scrapy.http import Response
# 声明response类型,帮助IDE完成自动补全
def parse(self, response: Response):
pass
@seozed
seozed / Convert unicode to normal string.py
Last active May 11, 2020
[转换unicode字符串为正常字符串] 如\xa0... #unicode
View Convert unicode to normal string.py
import unicodedata
s = 'T-shirt\xa0\xa0短袖圆领衫,\u3000体恤衫\xa0买一件\t吧'
unicodedata.normalize('NFKC', s)
# T-shirt 短袖圆领衫, 体恤衫 买一件 吧
# 日常爬虫抓取数据中常遇到此类问题,使用率较高
def unicode_normalize(unistr, form='NFKC'):
"""
@seozed
seozed / jsonpath.py
Last active May 11, 2020
[jsonpath] 优化提取方法 #jsonpath
View jsonpath.py
from jsonpath import jsonpath as _jsonpath
def jsonpath(obj, expr):
"""
优先项:如果匹配到的结果只有一个,则直接pop出该结果
"""
result = _jsonpath(obj, expr)
if isinstance(result, list) and len(result) == 1:
@seozed
seozed / mysql_connect.py
Last active May 11, 2020
[Database connect in python] #mysql #python
View mysql_connect.py
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
db='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
@seozed
seozed / clean html.py
Last active May 11, 2020
优雅的过滤HTML
View clean html.py
from w3lib.html import remove_tags, strip_html5_whitespace
# keep参数为需要保留的标签名称
remove_tags(text, keep=('img',))
# 移除HTML标签,并删除前后的空白字符
def clean_tags(text, which_ones=(), keep=(), encoding=None) -> str:
if not text:
return None
content = remove_tags(text, which_ones, keep, encoding)
@seozed
seozed / update_params_for_link.py
Last active Apr 23, 2020
update_params_for_link
View update_params_for_link.py
You can’t perform that action at this time.