Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1689871
  • 博文数量: 410
  • 博客积分: 9563
  • 博客等级: 中将
  • 技术积分: 4517
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-03 19:59
个人简介

文章分类

全部博文(410)

文章存档

2017年(6)

2016年(1)

2015年(3)

2014年(4)

2013年(32)

2012年(45)

2011年(179)

2010年(140)

分类: Python/Ruby

2011-01-27 16:33:39


2009年1月3日

可以查询五笔的网站很多,还是觉得不方便,本来想利用一个字典,实现本地查询,结果没找到。下面是一个用Python写的从在线查询汉字五笔编码和拼音的程序。

#!/usr/bin/env python #coding=utf-8 #author: Jianjun Kong #website: import urllib,cookielib,urllib2,httplib import sys,string,os web_url = "" web_url += "wb/wb.asp?" str=string.join(sys.argv[1:],'') def init(): cookie = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) exheaders = [("User-Agent","Firefox/3.05 (X11; Linux x86_64; U;en)"),("Connection","Keep-Alive"),("Referer",""),("Accept","text/html,application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg,image/gif, image/x-xbitmap, */*;q=0.1"),("Accept-Charset","iso-8859-1,utf-8, utf-16, *;q=0.1"),("Cookie2","$Version=1"),] opener.addheaders = exheaders urllib2.install_opener(opener) return opener def search(opener): global web_url,str body = (("querykey",str.decode('utf-8').encode('gb2312')),) ret = opener.open(web_url,urllib.urlencode(body)) str=ret.read() str=str.decode('gb2312').encode('utf-8') f=open("/tmp/wubi.tmp","w") f.write("%s" %(str)) f.close() def main(argv=None): opener=init() search(opener) cmds=''' sed -i -e '1,/
//g;/
阅读(2091) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~