发个有点用的py程序。这个将从wwenglish网站下载VOA Special English 资料
# -*- coding: utf-8 -*-
"""
Author: metaphy
2008-3-10
"""
import urllib, httplib, urlparse
import re
import random
SITE = "http://www.wwenglish.com"
"""处理每个页面"""
def handleSubpage(url):
# print url
save = "D:\\English\\people\\"
htmlFile = getFileName(url) + ".htm"
mp3File = getFileName(url) + ".mp3"
#Get the html file
download(url,save + htmlFile)
page = urllib.urlopen(url)
html = page.readlines()
page.close()
pattern = r"""href="?(\S+)\.mp3"""
re.compile(pattern)
for line in html:
matches = re.findall(pattern, line)
if matches != None:
for m in matches :
mp3url = SITE + m + ".mp3"
# print mp3url
download(mp3url,save + mp3File)
break
""" Get file name from URL"""
def getFileName(url):
arr = []
arr = url.split ("/")
name = arr.pop()[0:-4]
return name
"""根据url下载文件 """
def download(url,fileName):
print url
urllib.urlretrieve(url, fileName)
print "Save file succeed!"
def main():
url = "http://www.wwenglish.com/en/voa/spec/people_in_america.htm"
try:
page = urllib.urlopen(url)
html = page.readlines() #
page.close()
pattern = r"""href="/en/voa/spec/2007/?(\S+)\.htm"""
re.compile(pattern)
for line in html:
matches = re.findall(pattern, line)
if matches!=None:
for subpage in matches:
subpage = SITE + "/en/voa/spec/2007/" + subpage + ".htm"
# print subpage
handleSubpage (subpage)
except:
print "Err: main() error!"
return
main()
下面这个是下载VOA Standard English的一个py脚本:
# -*- coding: utf-8 -*-
"""
Author: metaphy
2008-5-4
"""
import urllib, httplib, urlparse
import re
import random
SITE = "http://www.51voa.com/"
SITE_MAINPAGE = "VOA_Standard_2.html"
DOWNLOAD_FOLDER = "D:\\English\\VOAStandard\\"
"""处理每个页面"""
def handleSubpage(url):
try:
print "URL:"+url
title = getFileName(url)
htmlFile = title + ".html"
mp3File = title + ".mp3"
#Get the html file
download(url, DOWNLOAD_FOLDER + htmlFile)
page = urllib.urlopen(url)
html = page.readlines()
page.close()
pattern = r"""<EMBED src="/?(\S+)\.mp3"""
re.compile(pattern)
for line in html:
matches = re.findall(pattern, line)
if matches != None:
for m in matches :
mp3url = SITE + m + ".mp3"
# print mp3url
download(mp3url,DOWNLOAD_FOLDER + mp3File)
break
except:
print "handleSubpage(url) error!"
return
""" Get file name from URL"""
def getFileName(url):
try:
page = urllib.urlopen(url)
html = page.readlines()
page.close()
pattern = """<title>.*</title>"""
re.compile(pattern)
for line in html:
# print line
matches = re.findall(pattern, line)
if matches!=None:
for title in matches:
title = title[7:-39]
return title
return ""
except:
print "getFileName(url) error!"
return
"""根据url下载文件 """
def download(url,fileName):
print url
urllib.urlretrieve(url, fileName)
print "Save file succeed!"
def main():
try:
page = urllib.urlopen(SITE+SITE_MAINPAGE)
html = page.readlines()
page.close()
pattern = r"""href="/VOA_Standard_English/?(\S+)\.html"""
re.compile(pattern)
for line in html:
matches = re.findall(pattern, line)
if matches!=None:
counter = 0
for subpage in matches:
counter = counter + 1
if counter >=4 and counter <= 50:
subpage = SITE + "VOA_Standard_English/" + subpage + ".html"
handleSubpage (subpage)
except:
print "Err: main() error!"
return
main()
分享到:
相关推荐
VOA Special English words
VOA Special English 最常用的1500个单词,适合初学的朋友
VOA 听力 VOA\VOA-SP\SpecialEnglish
VOA Special English 学习总攻略
Word Book a-z VOA Special English EDITION PDF版本,非扫描版,值得珍藏
This is the VOA Special English Development Report. Sometimes it takes an engineer to help a village. In poor communities, that help may come from volunteers with a group called Engineers Without ...
VOA Special English2010年01月份听力材料特别适合英语初学者,也适合英语听力比较薄弱的英语学者,听力材料涉及教育、农业、科技、热点新闻等,发音地道、标准!
EDUCATION REPORT - On the Web, College Classes With No Charge (or Credit)
[2009年.VOA.Special.English.每日精听flash课件].2009050101
voa,special,english.doc
SPECIAL_ENGLISH_2009-03-03-voa2
VOA Special English 节目内容题材广泛,如果能坚持长期学习,你不仅能扩充知识面,增加词汇量,提高阅读能力,还能在潜移默化中提高写作水平。那么你是怎么样使用 VOA Special English 来学习提高英语水平的呢?...
英语中高级学习者学习的很好资料。也可以作为了解英语文化的一个参考。
[2009年.VOA.Special.English.每日精听flash课件].2009050201
VOA英文广播时刻表。包括 Standard English , 和Special English。
Coming to Terms With Academic Titles at US Colleges。
1500 BASIC VOCABULARY VOA Special English
美语三级跳,Go,English.doc
英语voa听力 很好很好的资料哦,赶紧都来下吧