PamieÄ£¿éÏê½â python²Ù×÷ieä¯ÀÀÆ÷
from http://blog.alexa-pro.cn/?p=315
´ËÎĵµÊ¹ÓÃƽ̨Ϊ cPAMIE Build 2.0,ºÍ֮ǰµÄ°æ±¾ÓÐÃ÷ÏԵIJî±ð,¾ßÌå¿ÉÖ±½Ó¿´cPAMIE.py Ô´Âë
ÏÂÃæÊÇһЩ³£Óõķ½·¨
ie.navigate('http://blog.alexa.cn') ÓÃÀ´·ÃÎÊÒ»¸öÁ´½Ó¡£
ie.linkClick('linkname') ´ò¿ªÕâ¸öÒ³ÃæÖеÄÒ»¸öÁ¬½Ó ²ÎÊý: name»ò id
ie.textBoxSet('labels','python') ÉèÖÃÒ»¸öÎı¾ÓòµÄÖµ¡£µÚÒ»¸ö²ÎÊýΪÎı¾ÓòµÄÃû³Æ,µÚ¶þ¸ö²ÎÊýΪҪÊäÈëµÄÖµ£¬
ie.buttonClick('btnA') ÓÃÀ´Ä£Äâµã»÷°´Å¥ ²ÎÊýÊÇ°´Å¥µÄÃû×Ö
ie.findText(unicode("µÇ¼", "cp936")) ²éÕÒÎı¾ Èç:
if (True == ie.findText(unicode("·Ç·¨µÇ¼", "cp936"))):
print "·Ç·¨µÇ¼!"
else:
print "µÇ¼³É¹¦!"
ie.quit() -- ¹Ø±Õ´ò¿ªµÄie
ie.goBack() -- ºóÍË
ie.refresh() -- Ë¢ÐÂ
ie.buttonGetValue('wp-submit','value') µÃµ½Ò»¸öÎÞËصÄÆäËüÖµ,µÚÒ»¸ö²ÎÊýΪÄãÖªµÀµÄÔªËØÊôÐÔÈç:id, name, value µÈ,µÚ¶þ¸ö²ÎÊýΪÄãÒªµÃµ½µÄÕâ¸öÔªËصÄÆäËüÖµ,ÕâÑùÈç¹ûÄãÖªµÀname,¾Í¿ÉµÃµ½id,valueµÈ,Èç¹ûÖªµÀname¾Í¿ÉÖªµÀid,value.....
ie.buttonClick('down') Õâ¸ö·½·¨µÄ²ÎÊý¿ÉÒÔÊÇname,ID,VALUEµÈ,×¢:NAMEºÍVALUEΪÖÐÎÄʱ¼Ç×ÅתÂëÈç:unicode("¶ÏÏß", "cp936")
ie.elementsGetList(tag, [filter], ) ·µ»ØÒ»¸ö¹ýÂ˺óµÄÔªËØÁбí
·û¼¸¸öÀý×Ó:
Õâ¸öÊǽ«ÎÄÕÂÌá½»¸øGOOGLEÊղؼеĽű¾,Ó÷¨ postgoogle.py http://blog.alexa-pro.cn/index.php
import cPAMIE,re,string,time,sys
ie= cPAMIE.PAMIE()
args = sys.argv
ie.navigate(args[1])
Title=ie.locationName().strip()
Title=Title.replace('GGclub','').replace(' Blog Archive ','')
ie.navigate('https://www.google.com/accounts/Logout?continue=http://www.google.com/intl/zh-CN/&hl=zh-CN')
ie.navigate('https://www.google.com/accounts/ServiceLogin?hl=zh-
CN&continue=http://www.google.com/bookmarks/mark%3Fop%3Dadd%26bkmk%3Dhttp%253A%252F%252Fblog.alexa-pro.cn%252F%
26title%3DGGclub&nui=1&service=bookmarks')
ie.textBoxSet('Email','yingguang08@gmail.com')
ie.textBoxSet('Passwd','*******')
ie.buttonClick('signIn')
ie.textBoxSet('title',Title)
ie.textBoxSet('bkmk',args[1])
ie.textBoxSet('labels','python')
ie.textBoxSet('annotation','python linux')
ie.buttonClick('btnA')
½âÊÍ:
ÏÈÖ´Ð
Ïà¹ØÎĵµ£º
ÉÏһƪÀïµÄLAMEÏîÄ¿ÒѾչʾÁËpythonÈçºÎÓëCÓïÑÔ½»»¥£¬µ«³ÌÐòÈÔ²»¹»ÀíÏ룬ÔÚpythonÕâÒ»¶Ë½ö½öÊÇ´«µÝÔ´ÎļþºÍÄ¿±êÎļþµÄ·¾¶£¬ÔÙµ÷ÓÃCÄ£¿éµÄencode·½·¨À´½øÐбàÂ룬µ«ÎÊÌâÔÚÓÚÄãÎÞ·¨¿ØÖÆencodeº¯Êý£¬±ÈÈçÄãÏë±àÂëµÄÔ´ÎļþÈç¹û²»ÊÇÔʼÊý¾Ý£¬¶øÊÇwavÎļþ»òÕßÆäËû¸ñʽÄØ£¿¶ÔÓÚÕâ¸öÎÊÌ⣬ÓÐÁ½ÖÖ·½·¨¿ÉÒÔÑ¡Ôñ£¬Ò»ÖÖÄ£·ÂÇ°ÃæµÄCÄ£ ......
eval(str [,globals [,locals ]])º¯Êý½«×Ö·û´®strµ±³ÉÓÐЧPython±í´ïʽÀ´ÇóÖµ£¬²¢·µ»Ø¼ÆËã½á¹û¡£
ͬÑùµØ, execÓï¾ä½«×Ö·û´®strµ±³ÉÓÐЧPython´úÂëÀ´Ö´ÐÐ.Ìṩ¸øexecµÄ´úÂëµÄÃû³Æ¿Õ¼äºÍexecÓï¾äµÄÃû³Æ¿Õ¼äÏàͬ.
×îºó£¬execfile(filename [,globals [,locals ]])º¯Êý¿ÉÒÔÓÃÀ´Ö´ÐÐÒ»¸öÎļþ,¿´ÏÂÃæµÄÀý×Ó:
>>> ev ......
from http://blog.alexa-pro.cn/?p=189
1: os.listdir(path) //pathΪĿ¼
¹¦ÄÜÏ൱ÓÚÔÚpathĿ¼ÏÂÖ´ÐÐdirÃüÁ·µ»ØΪlistÀàÐÍ
print os.listdir('..')
Êä³ö£º
[a,b,c,d]
2: os.path.walk(path,visit,arg)
path £ºÊǽ«Òª±éÀúµÄĿ¼
visit £ºÊÇÒ»¸öº¯ÊýÖ¸Õ룬º¯ÊýÔ²ÐÎΪ£º
callback(arg,dir,fileList)
ÆäÖÐargΪΠ......