国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python自學-第12次作業

2019-11-08 01:48:53
字體:
來源:轉載
供稿:網友
#coding=utf8'''題目一: 寫一個網頁數據操作類。完成下面的功能:提示:需要用到urllib模塊get_httpcode()獲取網頁的狀態碼,返回結果例如:200,301,404等 類型為intget_htmlcontent() 獲取網頁的內容。返回類型:strget_linknum()計算網頁的鏈接數目。'''import urllibimport reclass mywebapp(object): def __init__(self): pass def get_httpcode(self,url): PRint url if not url.startswith('http://') and not url.startswith('https://'): raise TypeError,'Url must start with http:// or https:// .....' res = urllib.urlopen(url) page_status = res.getcode() print 'http status is %d' %page_status def get_htmlcontent(self,url): if not (url.startswith('http://') or url.startswith('https://')): raise TypeError, 'Url must start with http:// or https:// .....' content = urllib.urlopen(url) print content.read() def get_linknum(self,url): content = urllib.urlopen(url) print 'url is start' replace_content = content.read().replace(' ','') urls = re.findall(r'(http|ftp|https):////[/w/-_]+(/.[/w/-_]+)+([/w/-/.,@?^=%&amp;:/~/+#]*[/w/-/@?^=%&amp;/~/+#])?',replace_content,re.I) for i in urls : print i #print len(content.split('<a href=')) - 1myapp = mywebapp()print myapp.get_httpcode("http://www.baidu.com")print myapp.get_htmlcontent('http://www.baidu.com')print myapp.get_linknum('http://www.baidu.com')
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奉贤区| 定陶县| 高雄县| 天全县| 泸水县| 鲁山县| 图木舒克市| 噶尔县| 绍兴县| 游戏| 达日县| 乐都县| 乌拉特后旗| 富宁县| 景谷| 承德县| 塘沽区| 临夏市| 卢氏县| 友谊县| 永春县| 耿马| 舞钢市| 四平市| 绥宁县| 海伦市| 萝北县| 洛阳市| 小金县| 深水埗区| 繁昌县| 乐山市| 延安市| 哈巴河县| 平和县| 承德市| 定远县| 佛冈县| 昌图县| 织金县| 正镶白旗|