随笔分类 -  python

很好玩啊!
摘要:# -*- coding: utf-8 -*-"""Created on Fri Aug 01 18:09:21 2014@author: omom"""import urllib2from bs4 import BeautifulSoupsrc="http://www.xiami.com/widg... 阅读全文
posted @ 2014-09-05 11:29 Come~on! 阅读(721) 评论(0) 推荐(0)
摘要:twisted.internet.reactor 是进行所有twisted事件循环的地方。reactor在1个python进程中只能有一个。在windows下用的是select。linux下epool。mac下是pool,这点和socketserver,tornado的都一样哈()。源码位于twis... 阅读全文
posted @ 2014-07-30 15:00 Come~on! 阅读(653) 评论(0) 推荐(0)
摘要:python 下有个wsgi的封装库.wsgiref.WSGI 指的是Web服务器网关接口(Python Web Server Gateway Interface)django的runserver用到了这个标准库,学习一下。。涉及到的几个模块:HTTPServer,SocketServer,mimetools.Message(分析HTTP请求中的headers),socket(必须的),threading(用来实现ThreadingServer),select(用来实现非阻塞accept)wsgi在python的web世界中是相当出名的。apache有个wsgi接口:mod_wsgi,所以只要 阅读全文
posted @ 2014-04-04 12:38 Come~on! 阅读(2160) 评论(0) 推荐(0)
摘要:先给答案:493827152我才开始想到的解法: #coding:utf8#问题:987654321的阶乘转换为12进制,结尾有多少个0?#我的解法:把每个元素分解到两个数组中去,然后结对取出来。结对数就是最后0的个数。。def i3m(num):#是不是3的倍数 return not b... 阅读全文
posted @ 2014-03-11 13:23 Come~on! 阅读(526) 评论(0) 推荐(0)
摘要:网页登录,默认用户名和密码相同。import urllibimport reimport time_mydata=r"userid={num}&passwd={num}&chap=0&serivce=internet&random=internet&login=%B5%C7%C2%BC"id_lis... 阅读全文
posted @ 2014-03-11 11:30 Come~on! 阅读(527) 评论(0) 推荐(0)
摘要:下面的是server端:把IP改成自己的局域网IP: #coding:utf8import socket,selectimport SocketServerimport hashlib,base64,timefrom pprint import pprint#author:lijimdef f(key): s=key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11" sha1=hashlib.sha1(s) dig=sha1.digest() return base64.encodestrin... 阅读全文
posted @ 2014-03-11 11:26 Come~on! 阅读(876) 评论(2) 推荐(0)
摘要:在windows中使用,输入有关信息查询社工库,本来是网页版的,我把ajax请求提取出来。粗略的封装下,挺好玩。#coding:utf8import urllib2,urllibfrom BeautifulSoup import BeautifulSoupqueryword=raw_input(u"输入查询的字符串:\n".encode('gbk'))def f(queryword): q=lambda x:urllib.quote(x.decode('gbk').encode('utf8')) url="http: 阅读全文
posted @ 2014-03-11 11:20 Come~on! 阅读(1324) 评论(0) 推荐(0)
摘要:windows下py文件编码:当print 时遇到unicode 会根据系统编码转换,而raw_input 中的输出遇到unicode编码是不会的转码的,会报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)因为uncode的编码的第一个字符大于128(0x7f)下面的实验能证明: 1 #coding:utf8 2 a=u'你好' 3 print 'with u:',buffer(a) 4 阅读全文
posted @ 2014-03-11 10:58 Come~on! 阅读(709) 评论(0) 推荐(0)
摘要:scrapy是个好玩的爬虫框架,基本用法就是:输入起始的一堆url,让爬虫去get这些网页,然后parse页面,获取自己喜欢的东西。。用上去有django的感觉,有settings,有field。还会自动生成一堆东西。。用法:scrapy-admin.py startproject abc 生成一个project。 试试就知道会生成什么东西。在spiders包中新建一个py文件,里面写自定义的爬虫类。自定义爬虫类必须有变量domain_name和start_urls,和实例方法parse(self,response)..它会在 Scrapy 查找我们的spider 的时候实例化,并自动被 Sc 阅读全文
posted @ 2013-09-13 21:40 Come~on! 阅读(6350) 评论(0) 推荐(0)
摘要:The Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Althoug 阅读全文
posted @ 2013-05-07 10:13 Come~on! 阅读(178) 评论(0) 推荐(0)
摘要:http://zc.qq.com/chs/index.html哈哈。一句代码注册成千上万个qq号。。 阅读全文
posted @ 2013-05-02 20:22 Come~on! 阅读(468) 评论(0) 推荐(0)
摘要:安装过SIP执行python ./configure 时出错提示:Determining the layout of your Qt installation...Error: Failed to determine the layout of your Qt installation. Try again usingthe --verbose flag to see more detail about the problem.解决办法:后边加 -q qmake路径,我电脑上为 qmake4-64文件 阅读全文
posted @ 2013-04-12 09:34 Come~on! 阅读(580) 评论(0) 推荐(0)
摘要:#下载url中的图片。关键在于re模块的匹配和对urllib库中函数的使用,没什么难度import urllibimport rehtml=Nonedef get_html(_url): if _url.startswith('http') or _url.startswith('HTTP'): url=_url else : url='http://'+_url page=urllib.urlopen(url) html=page.read() return htmldef get_urls(_html): url_reg='h... 阅读全文
posted @ 2013-03-21 15:23 Come~on! 阅读(362) 评论(0) 推荐(0)
摘要:11101111 10111011 10111111 00100000 00100000 00100000 00100000 11100101 10000010 10110010 11100110 10000101 10100010 11100011 10000000 10000001 11100101 10100110 10010010 11100101 10111111 10001100 11100011 10000000 10000001 11100110 10011010 10110100 11100110 10000000 10010010 11100011 10000000 100 阅读全文
posted @ 2013-03-19 15:55 Come~on! 阅读(1922) 评论(2) 推荐(0)