python 脚本 - 自动检测代理速度
这个脚本是在 python 环境下使用的,改的网上的一个脚本,可以检测代理中国(www.proxycn.com)上的HTTP代理列表,你也可以自己去上面找列表检测 代码: #!/usr/bin/python # -*- coding: utf-8 -*- # from: ubuntu.org.cn Copyright: GPLv2 import urllib import re from datetime import datetime import socket def findporxy(): url = "http://www.proxycn.com/html_proxy/http-1.html" f = urllib.urlopen(url) html = f.read() p = re.compile('clip\(\'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,4})\'\);') ips=set(p.findall(html)) socket.setdefaulttimeout(5) a={} for ip in ips: start=datetime.now() flag = checkproxy(ip) end=datetime.now() if flag: print ip,'花费',end-start,'时间'; a[end-start]=ip b=sorted(a) print '速度排序 :' i = 0 for ix in a: print 'No.',i,': ',a[b[i]] i = i + 1 def checkproxy(ip): try: proxies = {'http': 'http://'+ip} filehandle = urllib.urlopen("http://www.0x201.cn/moyo/speed_x.jpg", proxies=proxies) html=filehandle.read() if len(html)==80996: return True else: return False except: return False if __name__ == '__main__': findporxy() 下载
相关文档:
Python简单又功能强大。它注重的是如何解决问题,而不是编程语言的语法和结构。理想的脚本语言。适用于快速的应用程序开发。
Python是一种解释性语言。还是一种面向对象的语言。
有两种使用python运行你的程序的方式:
使用交互式的带提示符的解释器
使 ......
如果你对Python矩阵转置的实际应用操作方案的转置不知道如何进行下一步时,你就你需要转置一个二维数组,将Python矩阵转置的行列互换.
这样就可以完成你所需要的应用操作,以下是文章的具体操作。
你需要转置一个二维数组,将行列互换,讨论:你需要确保该数组的行列数都是相同的.比如:
arr
= [[1, 2,&nbs ......
# -*- coding: cp936 -*-
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('e:\\test.txt').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/ ......
本篇将介绍python中sys, getopt模块处理命令行参数
如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢?
需要模块:sys
参数个数:len(sys.argv)
脚本名: sys.argv[0]
参数1: sys.argv[1]
参数2: sys.argv[2]
test.py
1
import ......
Python太火了,不学点都感觉自己不是学计算机的,今天看了个不错的《简明python教程》,很不错。不过在学习过程中,居然发现了一个Python的bug,
#!/usr/bin/python
#coding=UTF-8
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
......