易截截图软件、单文件、免安装、纯绿色、仅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() 下载


相关文档:

Python中的OS模块

os模块提供了多数操作系统的功能接口函数.当os模块被导入后,它会自适应于不同的操作系统平台,如posix或NT系统平台,os模块会根据不同的平台进行相应的操作.本节内容将对os模块提供的函数进行详细的解读.
1.1 文件操作函数
1.1.1 open()函数提供创建、打开、修改文件的功能。
Example 1-1. Using the os Module to Rename ......

分享一个简单的python模板引擎


#coding:utf-
8
  
__author__="sdm"
  
__author_email='sdmzhu3@gmail.com'
  
  
__date__ ="$2009-8-25 21:04:13$"
  
  
''
'  
pytpl 类似
php的模板类  
  
&nbs ......

Python内部的线程实现

在Python中的线程运行实际是受到Interpreter的控制或者说牵制的。在Interpreter的核心函数
PyObject * PyEval_EvalFrameEx
(PyFrameObject *f, int
throwflag)
我们可以看到有一个全局变量_Py_Ticker来控制着线程对Interpreter的占有的,默认是Interpreter每执行一百条指令就会释放另一个全局变量interpreter_lock.
......

使用C语言扩展Python(五)

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

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号