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

一行 Python 实现并行化 — 日常多线程操作的新思路

Python 在程序并行化方面多少有些声名狼藉。撇开技术上的问题,例如线程的实现和 GIL,我觉得错误的教学指导才是主要问题。常见的经典 Python 多线程、多进程教程多显得偏“重”。而且往往隔靴搔痒,没有深入探讨日常工作中最有用的内容。 传统的例子 简单搜索下“Python 多线程教程”,不难发现几乎所有的教……

Continue reading

python模块paramiko与ssh

paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接。paramiko支持Linux, Solaris, BSD, MacOS X, Windows等平台通过SSH从一个平台连接到另外一个平台。利用该模块,可以方便的进行ssh连接和sftp协议进行sftp文件……

Continue reading

python pexpect模块封装ssh

很多时候需要批量在一批主机上执行某个操作时,利用python 可以很好的完成这个工作。如果在现网主机上没有部署自动化工具时,同时你又不想使用paramiko这样相对重量级的模块,你可以通过pexpect模块通过一个简单的spawn执行并交互完成一些简单的命令操作。 pexpect模块……

Continue reading

python torndb模块

一、torndb概述 torndb是一个轻量级的基于MySQLdb封装的一个模块,其是tornado框架的一部分。其项目主页为:https://github.com/bdarnell/torndb 。从tornado3.0版本以后,其已经作为一个独立模块发行了。可以通过easy_in……

Continue reading

Python MySQLConnector模块

MySQL Connector/Python 是 MySQL 官方提供的 Python 连接 MySQL 数据库的驱动程序.下载地址为: http://www.mysql.com/downloads/connector/python/,其为mysql官方推出的一个python数据库模块,相较于MySQLdb模块来说,其支持python3,而MySQLdb目前只……

Continue reading

python MySQLdb模块小结

一、编码问题 使用mysql 进行中文数据插入时,经常会遇到插入的数据变乱码的问题。这里以经常用的utf8 编码为例,需要在创建数据库时先指定编码为utf8 ,如下: 1create database test character set uft8; 在使用python MySQLdb进行连接时,使用以下代码: 1#!/usr/bin/python 2# encoding: utf-8 3import MySQLdb 4# 打开数据库连接 5db = MySQLdb.connect("localhost","root","361way","test",charset="utf8",init_command="set names utf8" ) 经测试,我在……

Continue reading

python MySQLdb模块

python连接mysql 的方案有oursql、PyMySQL、 myconnpy、MySQL Connector 等,不过本篇要说的确是另外一个类库MySQLdb,MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的。可以从:https://……

Continue reading

python图片采集

本例是一个通过BeautifulSoup模块解析处理后进行img下载的示例,可以指定下载的路径,代码如下: 1# ImageDownloader.py 2# Finds and downloads all images from any given URL recursively. 3# FB - 20140223 4import sys 5import os 6import urllib2 7from os.path import basename 8import urlparse 9from BeautifulSoup import BeautifulSoup # for HTML parsing 10urlList = [] 11# recursively download images starting from the root URL 12def downloadImages(url, level): # the root URL is level 0 13 # do not go to other websites 14 global website 15 netloc = urlparse.urlsplit(url).netloc.split('.') 16 if netloc[-2] + netloc[-1] != website: 17 return 18 global urlList 19……

Continue reading

三个多线程采集网站图片的示例

采集代码一 1#! /usr/bin/env python 2# -*- coding: utf-8 -*- 3import os ,sys ,urllib2,socket 4import re 5import time 6from threading import Thread 7from Queue import Queue 8DOWNLOAD_BASEDIR = os.path.join(os.path.dirname(__file__), 'download') #保存地址 9socket.setdefaulttimeout(30) 10THREAD_COUNT = 5 #线程数量 11def md5sum(s): 12 try: 13 import hashlib 14 m = hashlib.md5() 15 m.update(s) 16 return m.hexdigest() 17 except: 18 import md5 19 m = md5.new() 20 m.update(s) 21 return m.hexdigest() 22class spiderList(Thread): 23 def __init__(self ,queue): 24 Thread.__init__(self) 25 self.queue = queue 26 def run(self): 27 pages = [] 28 #这个网站列表的页数从第1页到第117页 29 for i in range(1,117): 30 pages.append('http://xxx.com/?page=%s' % i) 31 self.queue.put(pages) 32 self.queue.task_done() 33class spiderDetail(Thread): 34 def __init__(self,queue): 35 Thread.__init__(self) 36 self.queue =……

Continue reading

python pycurl模块

一、pycurl概述 PycURl是一个C语言写的libcurl的python绑定库。libcurl 是一个自由的,并且容易使用的用在客户端的 URL 传输库。它的功能很强大,在PyCURL的主页上介绍的支持的功能有:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. libcurl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy……

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