pythonʵÏֵķÒë½Å±¾
½ñÌìͻȻÓÐÒ»¸öÏë·¨£¬¾ÍÊÇÏë×Ô¼ºÐ´Ò»¸ö·Òë½Å±¾¡£¿ÉϧGoogleÌṩµÄAPIÊǹ©ÍøÂçÓ¦Óõġ£¸ÕºÃÔÚ¡¶dive into python¡·ÀïÃæÕâ±¾ÊéÀïÃæ¿´µ½ÈçºÎ´ÓHTMLÎĵµÖÐÌáÈ¡³öÀ´×Ô¼ºÏëÒªµÄÄÚÈÝ£¬ÄÇÕâÑùµÄ»°£¬¿É²»¿ÉÒÔÄ£Äâä¯ÀÀÆ÷À´·¢ËÍÏë·ÒëµÄ¾ä×Ó£¬È»ºóÔÙ½ÓÊÕ·µ»Ø½á¹ûºóµÄHTMLÔ´Â룬×îºó´ÓÖÐÌáÈ¡³ö·ÒëµÄ½á¹ûÄØ£¿¡¡¡¡ÆäʵÊÇÐеģ¬ÒòΪÀûÓÃpython¿ÉÒÔÄ£Äâä¯ÀÀÆ÷µÄÐÐΪ£¬ÏòGoogle·ÒëµÄÖ÷Ò³·¢ËÍÏëÒª·ÒëµÄ¾ä×Ó¡£ÏÂÃæÊǾßÌåµÄ´úÂ룺
PythonÓïÑÔ: Codee#7671
1 import urllib,urllib2
2
3 values={'hl':'zh-CN','ie':'utf8','text':text,'langpair':"en|zh-CN"}
4 url='http://translate.google.cn/translate_t'
5 data = urllib.urlencode(values)
6 req = urllib2.Request(url, data)
7 req.add_header('User-Agent', "Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html)")
8 response = urllib2.urlopen(req)
¡¡¡¡ÉÏÃæ×î¹Ø¼üµÄÊÇtextÕâ¸ö±äÁ¿£¬ÖµÎªÏë·ÒëµÄ¾ä×Ó¡£ºóÃæµÄlangpairµÄÖµÊÇÓïÑÔ¶Ô£¬ÕâÀïÊÇÓ¢ÎÄ·Òë³É¼òÌåÖÐÎÄ£¬¿ÉÒÔ×ÔÓɸĶ¯¡£ÏÂÃæ¾ÍҪʵÏÖÒ»¸öÀàÀ´È¡³öÎÒÃÇÏëÒªµÄ·Òë½á¹û£¬Õâ¸öÀàÒª´ÓSGMLParserÅÉÉú³öÀ´£¬SGMLParserÊÇÔÚsgmllib.pyÖаüº¬µÄ¡£
PythonÓïÑÔ: Codee#7673
01 from sgmllib import SGMLParser
02
03 class URLLister(SGMLParser):
04 def reset(self):
05 SGMLParser.reset(self)
06 self.result = []
07 self.open = False
08 def start_div(self, attrs):
09 id = [v for k, v in attrs if k=='id']
10 if 'result_box' in id:
11 self.open = True
12 def handle_data(s
Ïà¹ØÎĵµ£º
pythonÖеıàÂë
ÔÎÄ£ºhttp://users.ir-lab.org/~liulong/blog/archives/001962.html
¼ÆËã»úÒÔ0,1¶þ½øÖÆλÀ´´æ´¢ÐÅÏ¢,ËùÒÔ×Ö·ûÔÚ¼ÆËã»úÖеıíʾҲÊǶþ½øÖÆλ,ÄÇÿ¸ö×Ö·ûËù¶ÔÓ¦µÄ¶þ½øÖÆλÊÇʲô,ÔÚ¿ªÊ¼µÄ¼ÆËã»úÖÐÒòΪֻ¿¼ÂÇÓ¢Óï, ËùÒÔ²»³¬¹ý256¸ö×Ö·û,¼´ÓÃÒ»¸ö×Ö½Ú(8bit)¾Í×ã¿ÉÒÔ±íʾËùÓеÄ×Ö·û,Õâ¸ö¶ÔÓ¦¹Øϵ¾ÍÊǶÔ×Ö·ûµ ......
ÔÎÄ
PythonºÍC·Ö±ðÓÐן÷×ÔµÄÓÅȱµã£¬ÓÃPython¿ª·¢³ÌÐòËٶȿ죬¿É¿¿ÐԸߣ¬²¢ÇÒÓÐÐí¶àÏÖ³ÉÄ£¿é¿É¹©Ê¹Ó㬵«Ö´ÐÐËÙ¶ÈÏà¶Ô½ÏÂý£»CÓïÑÔÔòÕýºÃÏà·´£¬ÆäÖ´ÐÐËٶȿ죬µ«¿ª·¢Ð§Âʵ͡£ÎªÁ˳ä·ÖÀûÓÃÁ½ÖÖÓïÑÔ¸÷×ÔµÄÓŵ㣬±È½ÏºÃµÄ×ö·¨ÊÇÓÃPython¿ª·¢Õû¸öÈí¼þ¿ò¼Ü£¬¶øÓÃCÓïÑÔʵÏÖÆä¹Ø¼üÄ£¿é¡£±¾ÎĽéÉÜÈçºÎÀûÓÃCÓïÑÔÀ´À©Õ¹PythonµÄ¹¦ ......
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊܺÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨Ìص㣬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óá£
ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó¹¦ÄÜ£º
Python£¨ÅÉÉ£©£¬ËüÊÇÒ»¸ö¼òµ¥µÄ¡¢½âÊÍÐ͵ġ¢½»»¥Ê½µÄ¡¢¿ÉÒÆÖ²µÄ¡¢ÃæÏò¶ÔÏóµÄ³¬¸ß¼¶ÓïÑÔ¡£Õâ¾ÍÊǶÔPython ......
PythonÓïÑÔ
: µ¼³öÓÊÏäÀïµÄÁªÏµÈË£ºÖ§³ÖGmail£¬126£¬ÍøÒ×£¬ËѺü£¬Hotmail£¬ÐÂÀË£¬ÑÅ»¢£¬MSN
#!/usr/bin/env python
#coding=utf-8
from
BeautifulSoup
import
BeautifulSoup
import
os
,
urllib
,
urllib2
,
pdb
import
cookielib
import
httplib
import
csv
,
re
GDATA_URL
=
'/accoun ......
¼òµ¥¼ÓÃÜ£¬ÓÃpythonÀ´Ð´Ð´¡£
#coding=utf-8
'''
Description: ¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ
Environment: python2.5.x
Author:idehong@gmail.com
'''
import os
import sys
class Code(object):
'''¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ'''
def __init__(self, key = "idehong@gmail.com"):
self.__src_key ......