易截截图软件、单文件、免安装、纯绿色、仅160KB

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() 下载


相关文档:

使用C语言扩展Python(五)

上一篇中我们在python端的做法是每次读取一个数据块,然后将这个数据块传递进C扩展模块中去,但对于目标文件的数据写入是在C扩展模块中完成的,但其实可以更面向对象一点,不是吗?原来outfp是一个文件指针,不如改成一个从Python中传递一个文件对象到C模块里去,这个文件对象有自己的write方法,这样在C扩展模块中你就可以 ......

python join的用法

>>> a="abcd"
>>> ",".join(a)
'a,b,c,d'
>>> "|".join(['a','b','c'])
'a|b|c'
>>> ",".join(('a','b','c'))
'a,b,c'
>>> ",".join({'a':1,'b':2,'c':3})
'a,c,b' ......

python中eval, exec, execfile,和compile


eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果。
同样地, exec语句将字符串str当成有效Python代码来执行.提供给exec的代码的名称空间和exec语句的名称空间相同.
最后,execfile(filename [,globals [,locals ]])函数可以用来执行一个文件,看下面的例子:
>>> ev ......

vc中调用python代码

运行一句python命令
对vc设置路径
include:D:\PYTHON31\INCLUDE
lib:D:\PYTHON31\LIBS
#include "stdafx.h"
#include "python.h"
int main(int argc, char* argv[])
{
 Py_Initialize() ;
 PyRun_SimpleString("print('Hello')");
 //PyRun_SimpleString("print(dir())");
 Py_Finalize();& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号