第一个完整的python程序---统计python3的所有包中,以哪个字母开头的最多?
2014-03-11 17:19
567 查看
看了几天dive into python3,想不到写出来的第一个程序却是python2.7的。
太久太久没有编程,python更是刚接触几天,所以写出来的程序真是够丑陋,相信以后水平提高了,几行代码就能搞定。
先看代码:
View Code
它来自于这里:
http://blog.csdn.net/infoworld/article/details/9337619
太久太久没有编程,python更是刚接触几天,所以写出来的程序真是够丑陋,相信以后水平提高了,几行代码就能搞定。
先看代码:
#! encoding=utf-8 import urllib2 import re import os def Download(url,output): print "downloading..."+url response = urllib2.urlopen(url) resourceFile = open(output,"wb") resourceFile.write(response.read()) resourceFile.close() print "downloaded" def Action(url,ext = "pdf",output = "."): #1.domain index = url.rfind("/"); domain = url[0:index+1]; print domain request = urllib2.Request(url) response = urllib2.urlopen(request) #2.content content = response.read() # print content #3.resource mode = '\"([^\"]+'+ext+')\"' pattern = re.compile(mode) strMatch = pattern.findall(content) size = len(strMatch) print "file num: "+str(size) for i in range(0,size,1): # print strMatch[i] one = strMatch[i] partIndex = one.rfind('/') if not one.startswith('http://'): if -1!=partIndex: directDir = one[0:partIndex+1] else: directDir = "" # print directDir try: os.makedirs(output+"/"+directDir) except Exception,e: pass fileUrl = domain+one fileOutput = output+"/"+one print fileUrl print fileOutput Download(fileUrl,fileOutput) else: print one print "........." print one[partIndex:] fileOutput = output+"/"+one[partIndex:] print fileOutput Download(one,fileOutput) #5.download if __name__=='__main__': print "download" url = "http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/"; Action("http://tech.qq.com/","jpg");
View Code
它来自于这里:
http://blog.csdn.net/infoworld/article/details/9337619
相关文章推荐
- 【Python】用Python来实现凑24的程序,续--实现统计功能,列举出所有情况
- Python 初学——V_Rename(第一个完整的python程序)
- 微信小程序css篇----所有属性(按字母排列:b开头)
- 微信小程序css篇----所有属性(按字母排列:c,d,e开头)
- java 正则表达式查找某段字符串中所有小写字母开头的单词并统计次数,按出现次数排序
- 微信小程序css篇----所有属性(按字母排列:a开头)
- 第一个python程序-blog数目统计
- 微信小程序css篇----所有属性(按字母排列:f 开头)
- 第一个Python程序
- 【Windows】Python教程小白版之Python安装及第一个Python小程序
- 第一个Python程序
- python3利用socket查看各大网站所用的WEB服务器程序,看看那个用得最多。
- 第一个python程序(os模块使用)
- 我的第一个Python网络程序
- 第一个Python程序
- 第一个Python程序——hello world
- 使用python写的代码行数统计程序
- python学习笔记一:python的配置和第一个程序
- python3----输出所有大小写字母及数字
- 使用idea写python第一个程序