ITeye博客

yuhai.china

yuhai.china · 共 67 篇文章

jsp中使用jdbc和dbcp一例

<%@ page contentType="text/xml;charset=gbk"%><%@ page import="org.apache.commons.dbcp.*" %><%@ page import="java.io.*" %><%@ page import="java.util.*" %><%@ page import="java.util.regex.*" %><%@ page import="java.sql.*" %><% PrintWriter pw = response.getWriter(); pw.write("<?xml version=\"1.0\" enc…

2009-06-26 13:46 · 评论(0) · Java · SQL · JDBC · MySQL · JSP

MapRunnable设计一例

[code="java"] package org.apache.nutch.fetcher; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import o…

2009-06-17 17:21 · 评论(0) · WAP · Apache · Mobile · Hadoop · XHTML

使用PIL和StringIO做图片resize

StringIO就是把内存里的数据封装成文件句柄 import os, sys import Image import StringIO size = 128, 128 outfile = 'D:/wallcoo-3.jpg' try: #im = Image.open('D:/wallcoo.jpg') fp=open("D:/wallcoo.jpg", "rb") buffer=fp.read() im = Image.open(StringIO.StringIO(buffer)) im.thumbnail(size) s = StringIO.StringIO() im.save(s,…

2009-04-28 17:00 · 评论(0) · C · C++ · FP · OS · C#

python中的正则表达式应用

[code="java"] f=open('wuqu.html','r') content=f.read() m=re.findall('[\w|\W]*?', content) print len(m) if m is None:return for i in range(1,len(m)): c=m[i] d=re.findall('', c) if d is None:continue if not len(d) == 4:continue name= re.search(">(.*?)<",d[0]).group(1) #name classify= re.search(">(.*?…

2009-04-08 10:56 · 评论(0) · C · C++ · 正则表达式 · C# · Python

Tkinter图形界面设计

#coding=gbk from Tkinter import * import pycurl import sys, re, md5, os, time, commands import pycurl import cStringIO as _StringIO import sys import shutil, urllib, urllib2 import socket,sqlite3 as sqlite import datetime, time from time import sleep site='12530' # MIME type accept_type = "*/*" # h…

2009-03-29 19:01 · 评论(0) · C · FP · Socket · Mobile · SQLite

python url编码

urllib2.quote(u'北京'.encode('utf-8'))

2009-03-29 12:07 · 评论(0) · Python

nutch搏斗之一

问题描述: 在用nutch1.0做generate 包括5亿url的crawldb时,它默认按照64M分块,分成777个map task,在运行的后期出现 Could not find taskTracker/jobcache/job_200903231519_0017/attempt_200903231519_0017_r_000051_0/output/file.out in any of the configured local directories 异常。 解决办法: 减小task数目,改成按照crawldb里面文件个数划分的策略: [code="java"] public sta…

2009-03-26 19:01 · 评论(2) · Java · Apache · JSP · 互联网 · Servlet

设计python版的爬虫

准备工作 安装Python2.5 安装easy_install,pycurl,lxml;建议使用firefox浏览器,可以方便的使用各 种调试插件。 基本知识 需要了解python中unicode的原理,以便掌握GBK和UTF-8的转换方法. 假设content是GBK编码,在python中,转换成UTF-8的方法如下: Content=Content.decode(‘gbk’).encode(‘utf-8’) 3 专业技能 需要熟练掌握xpath,强烈推荐在信息抽取时使用xpath,这是一种基于文档结构 的方法。优于使用正则表达式。正则表达式是一种字符串匹配的方法,难于维 护。经常用到的x…

2009-03-26 10:49 · 评论(0) · 浏览器 · FP · 正则表达式 · Firefox · Python

eclipse profile tool

http://www.eclipse.org/tptp/home/downloads/4.5.0/documents/quicktour/quick_tour.html Eclipse Test and Performance Tools Platform

2009-03-26 10:44 · 评论(0) · HTML · Eclipse · performance

python抓取

准备工作 可以使用Python2.5,推荐使用2.4,因为需要兼顾wkfs的接口。 安装easy_install,pycurl,lxml;建议使用firefox浏览器,可以方便的使用各种调试插件。 基本知识 需要了解python中unicode的原理,以便掌握GBK和UTF-8的转换方法. 假设content是GBK编码,在python中,转换成UTF-8的方法如下: Content=Content.decode(‘gbk’).encode(‘utf-8’) Python中的常用集合类包括链表list=[]和字典dict={}。 3 专业技能 熟练掌握xpath,强烈推荐在信息抽取时使用xp…

2009-03-20 09:59 · 评论(0) · 浏览器 · FP · 正则表达式 · Firefox · Python

nutch在单机windows下测试环境的配置

通常来说nutch应该部署在多台机器上,做并行抓取,那么配置nutch在单机windows下有什么意义呢?就是方便debug。 下面分步骤详述。 1.安装JDK 6,eclipse3.2以上版本 2.为eclise安装IBM mapreduce tools插件 [url]http://www.alphaworks.ibm.com/tech/mapreducetools[/url] 3.安装cygwin,并设置环境变量 4.下载nutch源代码,我使用的是最新的1.0版本 5.在eclipse中创建MapReduce Project工程。将nutch下的src/java下的所有代码复制到工程的…

2009-03-19 13:53 · 评论(0) · Java · Windows · Hadoop · IBM · Mapreduce

eclipse debug

f5 shenru f6 over f7 return

2009-03-18 14:39 · 评论(0) · Eclipse

利用lxml,得到html元素的绝对xpath路径

#coding=gbk import lxml.etree import lxml.html as x f=open('f:/test.html','r') c=f.read() doc=x.document_fromstring(c) alist=doc.xpath("//a") for a in alist: tree=lxml.etree.ElementTree(a) print tree.getpath(a)

2009-03-13 16:05 · 评论(0) · HTML · C · C++ · C# · F#

mod_python headers_out

In mod_python it's: req.headers_out = "application/force-download" req.headers_out = "attachment; filename=%s" % filename #/usr/local/apache/htdocs/segmentMusic req.headers_out['content-disposition'] = 'handler; filename=%s.mp3' % random_num

2009-03-11 20:57 · 评论(0) · Java · Apache · Python

mod_python示例

from mod_python import apache def handler(req): req.content_type = "text/plain" req.write("Hello World!") return apache.OK

2009-03-10 12:01 · 评论(0) · Apache · Python