Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

python urllib urllib2 httplib ·ÃÎÊurlµÄÎÊÌâ

ÎÒÏëÓÃpython½âÎöÍøÒ³ÖеÄurl ÔÚÏÂÔØ֮ǰ, ÎÒÏëÏÈ·¢Ò»¸öheadÇëÇó ²»ÐèÒªÏÂÔØÕû¸öÍøÒ³, ÏÈ»ñµÃ¸ÃÍøÕ¾µÄheadÐÅÏ¢, ¶ÁȡһЩÐÅÏ¢Ö®ºó ÔÚµ÷ÓÃÕâЩ¿âµÄread·½·¨À´¶ÁÈ¡Õû¸öÍøÒ³ ¸ÃÔõô²Ù×÷ÄØ ¶àл
°ï¶¥ÁË

ÓÐÈËÄÜÖ¸½ÌÒ»ÏÂô ¶àл

e.g.,
...
try:
content = None
content = urllib.urlopen(_url).info()['Content-Type']
print "*"*10, content, _url, urllib.urlopen(_url).info()

stext = 'text/plain'

if content[0:len(stext)] == stext :
urllib.urlretrieve(_url, _dest)

except IOError:
return 0

...

urllib.urlopen(_url).info()ÊÇÖ»ÁÙʱÌá½»Ò»¸öheadÇëÇó, °ÑÒ³ÃæÍ·²¿downÏÂÀ´Ã´??

Ò²¾ÍÊÇ˵ ÎÒÔÚµ÷ÓÃurlopenµÄʱºò ÊÇdownÏÂÀ´Ò»²¿·ÖÍøÒ³ÐÅÏ¢»¹ÊÇ°ÑÕû¸öÍøÒ³ÐÅÏ¢¶¼downÏÂÀ´·Åµ½»º´æÖÐ,È»ºóÔÙµ÷ÓÃread½«Êý¾Ý´òÓ¡³öÀ´ÄØ? ÏÖÔÚÕâÀï²»Àí½âurlopenµÄ¹ý³Ì ÇëÖ¸½Ì ¶àлÁË

ÓÐÈËÄÜÖ¸½ÌÒ»ÏÂô ¶àл


Èç¹ûÓõÄÊÇ urllib2.urlopenÄØ ÊDz»ÊÇÒ²ÊÇÏÈdown¸öÍ·ÐÅÏ¢, È»ºóÔÚ readµÄʱºò²Å¿ªÊ¼ÔÙ´ÎÁ¬½ÓÍøÕ¾¿ªÊ¼down¾ßÌåÄÚÈÝÄØ? ¶àл


Ïà¹ØÎÊ´ð£º

python½Ì³ÌÖÐʹÓÃÔ´ÎļþµÄÎÊÌâ~~

ʹÓÃÔ´Îļþ

#!/usr/bin/python
# Filename : helloworld.py
print 'Hello World'

ÎÒÔõôҲ¿´²»¶®£¡Ö»ÊÇ×îºóÒ»ÐÐÎÒÖªµÀ~~Ç°ÃæÁ½ÐÐÊÇʲôÒâ˼ÄØ£¿
½Ì³ÌÉÏ˵Èç¹ûÄãʹÓÃIDLE£¬ÇëʹÓò˵ ......

³õѧPYTHON£¬´ó¼ÒÖ÷ÒªÓÃËüÀ´×öʲô

    ¸Õ½Ó´¥£¬¸Ð¾õ¹¦ÄܱȽÏÇ¿´ó£¬Ö÷ÒªÊÇÕ³ºÏÐԺ㬿ÉÒÔÓлú½áºÏÆäËûÓïÑÔ¡£µ«²»Ã÷°×ËüÖ÷ÒªÓ¦ÓÃÓÚʲôÁìÓò£¬Ö÷Òª×öÄÇ·½ÃæµÄ¶«¶«¡£¿ª·¢ERPϵͳÊÇ·ñ¿ÉÐУ¿
»ù±¾ÉÏʲô¶¼¿ÉÒÔ×ö

½ñÌìÈ¥¿´ÁËһϣ¬»ù±¾ÉÏʲô ......

IIS 7 python 2.6 cgi ÎļþÉÏ´«ÎÊÌâ

ÎÒÿ´ÎÉÏ´«µÄÎļþ¶Áµ½µÄÊý¾Ý¶¼²»ÕýÈ·¡£2M µÄͼƬ¶ÁµÃ10¶àK ¡£¡£ÄÄλ´óÏÀ¿ÉÒÔ°ï°ïÎÒ°¡¡£
#!D:\ProgrammerTools\python26\python.exe
#encoding=utf-8
import cgitb
import os
cgitb.enable()
import cgi,urllib ......

python ÔÚÍøÕ¾×¢²áÓû§

rt
Õâ¸öÔõôʵÏÖ£¬Ð»Ð»£¡

±ÈÈ磬ÎÒ·¢ÏÖij¸öÍøÕ¾ºÜºÃÍæ¡£ÎÒÏëÓÃpythonд¸ö³ÌÐò×¢²áµ½Õâ¸öÍøÕ¾ÉÏ¡£ÔõôʵÏÖ£¿

up¼ÌÐøµÈ»Ø¸´


ÒýÓÃ
¶Ô·½¿ÉÄÜÓз´auto»úÖÆ£¬±ÈÈçʶ±ðÂëµÈ¡£ËùÒÔÄãµÄ¹¤³ÌÁ¿¾Í´óÁË¡£
......

python¸ù¾Ýfeedparser¶ÁÈ¡xmlµÄʱ¼ä

feedparserµ¼ÈëÕâ¸ö°ü ¶ÁxmlµÄtitle£¬link ¶¼Ã»ÎÊÌâ ¾ÍÊÇʱ¼ä¶ÁÈ¡²»³öÀ´
´íÎó£º
print d['feed']['%s lastBuildDate']

return UserDict.__getitem__(self, realkey)
KeyError: ' ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ