采集內容常需要得到網頁返回的驗證碼做進一步處理
下面代碼是用python寫的用來獲取網頁http狀態碼的腳本
#!/usr/bin/python# -*- coding: utf-8 -*-#encoding=utf-8#Filename:states_code.py import urllib2 url = '//www.jb51.net/'response = Nonetry: response = urllib2.urlopen(url,timeout=5)except urllib2.URLError as e: if hasattr(e, 'code'): print 'Error code:',e.code elif hasattr(e, 'reason'): print 'Reason:',e.reasonfinally: if response: response.close()
新聞熱點
疑難解答