python urllib2 ץȡÍøÒ³ ÈçºÎ²¶»ñ¸÷ÖÖÒì³£ÄØ
ÎÒÓÃpythonµÄ urllib2À´×¥È¡ÍøÒ³ Ôõô²ÅÄܲ¶»ñ¸÷ÖÖ·µ»ØµÄÒì³£ÄØ?
ÓÐÈçÏ´úÂë:
Python code:
import urllib2
if __name__ == '__main__':
url = 'http://hh'
try:
urllib2.urlopen(url, timeout=5)
except URLError, e:
print e.reason
ÎÒ²¶»ñÒì³£ È´ÌáʾÕâÖÖ´íÎó:
except URLError, e:
NameError: name 'URLError' is not defined
ÊÇÔõô»ØÊ Ϊʲô˵ÎÒ䶨ÒåÄØ?
¸ÃÔõô¸Ä²Å¿ÉÒÔÄØ
»¹ÓÐ Âé·³¸æ֪һϠÍøÒ³¸÷ÖÖ·µ»Ø´íÎóÔõô²¶»ñÄØ
¿ÉÄÜÊÇûµ¼ÈëºÏÊʵĿâ
²»ÊÇÓиö¸üºÃµÄÀý×Óô
from urllib2 import Request, urlopen, URLError, HTTPError
req = Request(someurl)
try:
response = urlopen(req)
except HTTPError, e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except URLError, e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
else:
# everything is fine
Ïà¹ØÎÊ´ð£º
pythonºÍpyqtÒÔ¼°Eric4¶¼ÒѾÅäÖúÃÁË£¬´ò¿ªEric4д¸öpython³ÌÐò±ÈÈç¼òµ¥µÄ
print¡°hello£¬world¡±£¬Ôõô±àÒëÔËÐÐÁË£¬Start²Ëµ¥µÄËùÓÐÃüÁ³öÏÖºÍͼÖв¶àµÄ¶Ô»°¿ò£¬Ó¦µ±ÔõôÔËÐÐÁË£¿
Çó´ó¼ÒÖ¸½Ì
ûÓÐÈËÓà ......
ʹÓÃÔ´Îļþ
#!/usr/bin/python
# Filename : helloworld.py
print 'Hello World'
ÎÒÔõôҲ¿´²»¶®£¡Ö»ÊÇ×îºóÒ»ÐÐÎÒÖªµÀ~~Ç°ÃæÁ½ÐÐÊÇʲôÒâ˼ÄØ£¿
½Ì³ÌÉÏ˵Èç¹ûÄãʹÓÃIDLE£¬ÇëʹÓò˵ ......
ÒÑÖªPython ÖУº
s = unicode("²âÊÔ", "gb2312")
s = u'\u6d4b\u8bd5'
print s
²âÊÔ
ÔÚDelphiÀïÃæÈçºÎ½«\u6d4b\u8bd5ÕâÑùµÄ»¹Ô³ÉGb2312µÄºº×ÖÄØ£¿
ÕÒµ½¸ö·½·¨
......
>>> x=-1
>>> if x>0:
print ('11')
>>> else:
SyntaxError: invalid syntax (<pyshell#20>, line 1)
ÍøÉÏËѵÄÒ²ÊÇ£º
>>> x=int(input("Please ent ......
ÈçºÎʹÓÃpython,½«ÏÂÃæµÄÍøÒ³
http://quotes.money.163.com/corp/1034/code=600221.html
ÄÇÕÅ×ʲú¸ºÕ®±íץȡ³öÀ´£¬·¢µ½Ò»¸öÎı¾ÎļþÖУ¿
ÇëÁôÏÂqq,ÎÒ°ÝÄãΪʦ
Python code:
import re
import url ......