分类 perl/php/python/gawk/sed articles

php安装 Xcache 缓存扩展,降低服务器负载

php站点流量一旦上来,就可能导致服务器负载不太稳定,负载时不时会飙升好几倍甚至十几倍,访问就非常慢啦。而站点内的很多东西都可以进行缓存的,以wordpress为例,可以使用xcache做对象缓存扩展,memcached/redis做内存缓存。 一、XCache 简介 XCache 是一个国人开发……

Continue reading

python转换磁力链接为bt种子文件

前天,在 Python将BT种子文件转换为磁力链的两种方法 篇中根据网上的方法完成后bt种子转换为磁力链的过程,今天要做的是一个反过程,将磁力链转化为种子文件。 1、需要先安装python-libtorrent包 ,在ubuntu环境下,可以通过以下指令完成安装: 1# sudo apt-get install python-libtorrent 2、代码如下:……

Continue reading

python 列表去重

在抓取页面图片时,为避免重复抓取,将抓取的img结果(结果集是list类型的)通过集合去重。这里总结了下网上搜集到的几种方法。 一、方法1 1ids = [1,2,3,3,4,2,3,4,5,6,1] 2news_ids = [] 3for id in ids: 4 if id not in news_ids: 5 news_ids.append(id) 6print news_ids 思路看起来比较清晰简单 ,也可以保持之前的排列顺序。 二、方法2 通过set方法进行处理 1ids = [1,4,3,3,4,2,3,4,5,6,1] 2ids = list(set(ids)) 处理起来比……

Continue reading

Python将BT种子文件转换为磁力链的两种方法

BT种子文件相对磁力链来说存储不方便,而且在网站上存放BT文件容易引起版权纠纷,而磁力链相对来说则风险小一些。而且很多论坛或者网站限制了文件上传的类型,分享一个BT种子还需要改文件后缀或者压缩一次,其他人需要下载时候还要额外多一步下载种子的操作。 所以将BT种子转换为占用空间更小,……

Continue reading

python文件操作(一)基础文件操作

从本篇开始准备对python文件的操作做一个系统总结。基础文件操作包括文件的文件的读取、创建、追加、删除、清空;按行进行或字节读写文件等内容。 一、python file open方法 Python 打开文件语法为: f = open(name[, mode[, buffering]]) 各字段含义: name: 所要打开的文件的名称, mode:打开……

Continue reading

Python Tablib导出数据为Excel、JSON、CSV等格式

Tablib是一个与表格格式有关的Python库,支持以下导出格式: Excel (Sets + Books) JSON (Sets + Books) YAML (Sets + Books) HTML (Sets) TSV (Sets) CSV (Sets) 详细文档:http://python-tablib.org 示例 生成一个新数据集 1headers = ('first_name', 'last_name') 2data = [ 3 ('John', 'Adams'), 4 ('George', 'Washington') 5] 6data = tablib.Dataset(*data, headers=headers) 添加新行 1>>> data.append(('Henry', 'Ford')) 添加新列 1>>> data.append_col((90, 67, 83), header='age') 导出为JSON格式 1>>> print data.json 2[ 3 {……

Continue reading

python re清理html

代码 1def formatHtml(input): 2 regular = re.compile('<\bp\b[^>]*>',re.IGNORECASE) 3 input = regular.sub('<p>',input) 4 regular = re.compile('</?SPAN[^>]*>',re.IGNORECASE) 5 input = regular.sub('',input) 6 regular = re.compile('</?o:p>',re.IGNORECASE) 7 input = regular.sub('',input) 8 regular = re.compile('</?FONT[^>]*>',re.IGNORECASE) 9 input = regular.sub('',input) 10 regular = re.compile('</?\bB\b[^>]*>',re.IGNORECASE) 11 input = regular.sub('',input) 12 regular = re.compile('<?[^>]*>',re.IGNORECASE) 13 input = regular.sub('',input) 14 regular = re.compile('</?st1:[^>]*>',re.IGNORECASE) 15 input = regular.sub('',input) 16 regular = re.compile('</?\bchsdate\b[^>]*>',re.IGNORECASE) 17 input = regular.sub('',input) 18 regular = re.compile('<\bbr\b[^>]*>',re.IGNORECASE) 19 input = regular.sub('<br>',input) 20 regular = re.compile('</?\bchmetcnv\b[^>]*>',re.IGNORECASE) 21 input = regular.sub('',input) 22 regular = re.compile('<script[^>]*?>.*?</script>',re.IGNORECASE+re.DOTALL) 23 input = regular.sub('',input) 24 return input 是用re注意: 1、def sub(pattern, repl, string, count=0, flags=0): 第三个参数是count很容易误用成flags. 2、re.……

Continue reading

python strip_tags实现

Sometimes it is necessary to remove all (or some subset of) xml style tags (eg.) from a string. If you’re familiar with PHP, then you probably already know about the strip_tags() function. Here is a simple equivalent to strip_tags() written in Python. 1## Remove xml style tags from an input string. 2# 3# @param string The input string. 4# @param allowed_tags A string to specify tags which should not be removed. 5def strip_tags(string, allowed_tags=''): 6 if allowed_tags != '': 7 # Get a list of all allowed tag names. 8 allowed_tags_list = re.sub(r'[\/<> ]+', '', allowed_tags).split(',') 9 allowed_pattern = '' 10 for s in allowed_tags_list: 11 if s == '': 12 continue; 13 # Add all possible patterns for this tag to the regex. 14 if allowed_pattern != '': 15 allowed_pattern += '|' 16 allowed_pattern……

Continue reading

Python正则表达式指南

本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例。本文的内容不包括如何编写高效的正则表达式、如何优化正则表达式,这些主题请查看其他教程。 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分。正则表达式是用……

Continue reading

python twisted异步采集

对于大量的数据采集除了多线程,就只有异步来实现了。本文是通过twisted框架来实现异步采集,原文来自:http://oubiwann.blogspot.com/2008/06/async-batching-with-twisted-walkthrough.html 。 Async Batching with Twisted: A Walkthrough……

Continue reading

Latest articles

Categories

Tags

ACL AD AES AI AWS Ansible Atlassian Azure BMC Blockchain Brocade CDH5 CL210 Cobbler Confd C语言 DDOS DISTINCT DNS Duckdb EKS ELK GCP Ghost Git Glusterfs Go Godaddy Grafana HBA HCIE Hotspot HttpWatch IBM IIS IOS InfluxDB Ingress InnoDB JavaScript Jinja2 KVM Keepalived Mplayer MySQLdb Netlify OpenResty PM PostgreSQL QoS RH318 RH442 RHCA RHCE RHEV RSA SRE SecureCRT Statuscode SublimeText2 TC Telecom Tencentcloud VBA aira2 alpine android anpic apache apm apparmor appfog apr apt-get aria2 array atop audit awk awstats axel backdoor backup bamboo bash bat benchmark bigdata bin bind bitwise book bootstrap bsd c1000 cache capistrano catlog centos centos7 chatops chattr check_mk checkinstall cisco clearall clickhouse cloud-desktop cmdb cms collectd comm compress conver corosync cpu crontab crunchbang css curl date decode dell desktop devops df dhcp diff diskpart django docker dos2unix dpkg drupal etcd excel fail2ban fastcgi fdisk fiddler find firewalld flask flvtool ftp function fuser geek gin github gitlab glances golang google gooupadd graphviz gravatra grep grub2 hadoop haproxy hardware heartbeat helm hexdump hhvm history html http/html/web httplogs https huawei huaweicloud hugo icmp iconv ifconfig inotify iopp ipmitool iptables iredmail iscsi isito it-news java jdk jenkins jira join joomla k3s k8s kdump kernel kingate lamp last leetcode lib light-http linux linux高级篇 ln ls lsi lsof lvm lvs mac mail man mark markdown matplotlib maven memcached microservice mimikatz mkdocs mkpasswd mmonit mod_jk mongodb monit monitor mono moodle mosh mount mpm mrtg mtr my.cnf mysql mysqlbinlog mysqld_multi mysqldump mysqlhotcopy nagios nc nethogs nexus nfs nginx nmon nocatlog node.js nrpe ntfs ntop ntp obs ocr open-falcon openbox opencv openldap openssl openstack oracle oswatch paas pacemaker pam pandas parted pcp pcre pdf percona perl pexpect pgrep php php-fpm ping plsql develope postfix powershell prettify proc prometheus puppeteer pushd pwgen pxe pyecharts python python模块 radmin raid rdesktop read redhat redis redmine regex rh134 rhel7 rhel8 rm rman rootkit route rpm rpmforge rrdtool rsync rsyslog safe saltstack samba scapy screen sed selenium selinux seo seq session set shc sheepdog shell shopt sitemap skydns smokeping snffier snmp socket soft sort spider sql sqlserver squid ss ssh sshpass strace strings su sudo suse svn sysbench syslog-ng sysstat systemd t tar tcpcopy tcpdump tech telnet tengine test testlink threads time tmux tomcat touch tr tsar twisted ubuntu udev ulimit unix unixbench user-agent useradd varnish vbs vercel vi vim visudo vmstat vmware vnc voice vpn vscode vsftp vsftpd vue watchdog web webcam webistrano wget wiki windows wol wordpress workshop wsl x-windows xampp xcache xmllint xtrabackup yule yum zabbix zeromq zip zonetime zookeeper 下载工具 云主机 云原生 代理 加密 古意 吐槽 圈里圈外 娱乐 字符串函数 安全 平台架构 意林 推理 提权 故事汇 故障案例 数据结构 每日看点 民国史 生活 科学记录 站长管理工具 算法 管理 网站架构 翻墙 股票 行业 诗韵 负载均衡 远程管理 面试题

Links

Meta