复制代码 代码如下:#coding=utf-8 import os import sys import re import urllib URL_REG = re.compile(r‘(http://[^///]+)‘, re.I) IMG_REG = re.compile(r‘<img[^>]*?src=([/‘"])([^/1]*?)/1‘, re.I) def download(dir, url): ‘‘‘下载网页中的图片 @dir 保存到本地的路径 @url 网页url ‘‘‘ global URL_REG, IMG_REG m = URL_REG.match(url) if not m: print ‘[Error]Invalid URL: ‘, url return host = m.group(1)...
今天尝试使用python写一个网络爬虫代码,主要是想访问某个网站,从中选取感兴趣的信息,并将信息按照一定的格式保存早Excel中。此代码中主要使用到了python的以下几个功能,由于对python不熟悉,把代码也粘贴在下面。1, 使用url打开网站网页import urllib2data = urllib2.urlopen(string_full_link).read().decode('utf8')print data
2,使用正则表达式匹配
import re#一般的英文匹配
reg = """a href=\S* target='_blank' title=...
几行代码的小工具,用于进行如下转换TRANSACTIONS ON CLOUD COMPUTING=》Transactions On Cloud Computingorig = ‘TRANSACTIONS ON CLOUD COMPUTING‘
splited = orig.split(‘‘)
handled = ‘‘for word in splited:word = word[0] + word[1:].lower()handled += (‘‘ + word)
handled = handled[1:]
print handled
#handled is ‘Transactions On Cloud Computing‘ 原文:http://www.cnblogs.com/instant7/p/4295530.html
#coding utf-8#1、设计一个购物车程序,提示用户输入工资,工资输入后打开商品列表,提示用户选择购买的商品#2、选择商品后,如果余额足够,就购买成功,并打印商品列表,否则购买失败,显示余额
salary=int(input("请输入你的工资额度:"))goodsList=[[‘Sony彩电‘,3888],[‘Apple电脑‘,8999],[‘炒锅‘,199],["Iphone6",3888],["茶杯",77]]changGoodList=[]i=1print("你输入的商品如下:")for good in goodsList:print("%d---%...
分两部分:1 python脚本2 一个config.txt文件有机会在共享一下编译成exe的文件。
1、脚本#!/usr/bin/env pythonimport osimport sysimport socketimport msvcrtb = sys.platformarr=[]if ‘win*‘ == b:config = sys.path[0] + ‘\config.txt‘else:config = sys.path[0] + ‘/config.txt‘file = open(config,"r")for line in file.readlines():if line.startswith("#"):continueelse:arr.append((line.replace(‘\n‘,‘‘).spli...
http://www.cocoachina.com/ios/20160307/15501.html 什么?又要测试包!做iOS开发几年了,每天除了码代码,改Bug之外,最让我烦恼的莫过于测试的妹子跑过来:“刚才的Bug都改完了吧,再打个包吧”。然而对于这个自己应尽的义务我已经烦透了,先不说要配置各种参数什么的,光是用xcode打包时候clean代码,验证证书就让我焦头烂额,时不时还要翻个墙甚至要手机开个热点才能打包成功。每次打包顺利的话,也要7~8分钟,每天n个包,想早...
市面上有很多开源的监控系统:Cacti、nagios、zabbix。感觉都不符合我的需求,为什么不自己做一个呢用Python两个小时徒手撸了一个简易的监控系统,给大家分享一下,希望能对大家有所启发首先数据库建表建立一个数据库“falcon”,建表语句如下:
CREATE TABLE `stat` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`host` varchar(256) DEFAULT NULL,`mem_free` int(11) DEFAULT NULL,`mem_usage` int(11) DEFAULT NULL,`mem_to...
脚本如下: #!/usr/bin/env python
#coding:utf-8import wmi
import sys,time,platformdef get_system_info(os):"""获取操作系统版本。"""printprint "Operating system:"if os == "Windows":c = wmi.WMI ()for sys in c.Win32_OperatingSystem():print ‘\t‘ + "Version :\t%s" % sys.Caption.encode("UTF-8")print ‘\t‘ + "Vernum :\t%s" % sys.BuildNumberdef get_memory_info(os):"""获取物理内存和虚拟内存。"""printprint...
Python写的Web spider:<span style="font-size:14px;"># web spider
# author vince 2015/7/29
import urllib2
import re# get href content
pattern = '<a(?:\\s+.+?)*?\\s+href=\"([h]{1}[^\"]*?)\"'
t = set("") # collection of urldef fecth(url):http_request = urllib2.Request(url)http_request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134...
近来有些东西需要监控报警发邮件,然后在网上找了点材料,自己写了一个简单发送邮件的脚本,主要就是运用python的smtplib模块,分享给大家看一下: #!/usr/bin/env python# -*- coding: utf-8 -*-#导入smtplib和MIMETextimport smtplib,sysfrom email.mime.text import MIMETextdef send_mail(sub,content):##############要发给谁,这里发给1个人mailto_list=["1234567@gyyx.cn"]######################设置服务器,用户名、口令以...
querybook.pyfrom bs4 import BeautifulSoup
from lxml import html
import xml
import requests
import splider
class QuName:def __init__(self,number):self.number = numberdef getPageNum(self,url):f = requests.get(url) # Get该网页从而获取该html内容soup = BeautifulSoup(f.content, "lxml")try:pageNum = soup.find('div', class_="pagesnums").find('span').textprint('getPageNum执行成功')return int(pageNum[3:5])...
学了一下python正则表达式,写一个百度图片爬虫玩玩。当技术遇上心术不正的人,就成我这样的2B青年了。python3.6开发,在Windows下需要安装vc2015动态库。下载地址:http://www.cr173.com/soft/146014.html 1#/usr/bin/env python 2#Guoyabin 3#-*- coding:utf-8 -*- 4import re,os5import requests6 7 keyword=input(‘请输入搜索关键词:‘)8 os.chdir(‘C:\\Users\\Administrator\\Desktop\\‘)9if os.path.exists(keyword) ==Fal...
一、说明:1、利用Python的paramiko模块,调用远程的shell命令去修改相应文件。2、有一个专用配置文件,列出服务器清单。3、Python循环读取配置文件的服务器IP去连接它,并执行相应的命令。4、主要是有一个正则,匹配Zabbix agent中的IP设置。[root@mysql-m ~]# sed -i ‘s/^Server=[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/Server=33.66.88.99/g‘ zabbix_agentd.conf
脚本的内容如下:#! /usr/bin/env python
# -*- coding: utf-8 -*-
# ...
因为数据库增删改突然暴增,需要查询是那些表的操作特别频繁,写了一个用来分析bin-log的小工具,找出增删改查的表,并按照操作次数降序排列,以下是代码:#form因为数据库增删改突然暴增,需要查询是那些表的操作特别频繁,写了一个用来分析bin-log的小工具,,找出增删改查的表,并按照操作次数降序排列,以下是代码:#for mysql5.5 binlog
import os,sys
#python binlog.py binglog-0001 '2013-07-01 00:00:00' '2013-07-02 00:...
因为MySQL数据库增删改突然暴增,需要查询是那些表的操作特别频繁,写了一个用来分析bin-log的小工具,找出增删改查的表,并按照操作次数降序排列,以下是代码:
#for mysql5.5 binlog import os,sys #python binlog.py binglog-0001 ‘2013-07-01 00:00:00‘ ‘2013-07-02 00:00:00‘ def log_w(type,text): logfile = "%s.txt" % (type,text) #now = time.strftime("%Y-%m-%d %H:%M:%S") tt = str(text) + "\n" ...