编写python脚本-->批量下载淘宝 2012年ADC技术嘉年华PDF文件
2016-01-18 00:00
766 查看
摘要: 载的文件名和标题不对应,一个个改起来麻烦。写了个简单的python脚步,下载后文件名和标题名一致。
下载文件的地址:http://www.taobaotest.com/notices/82
下载文件的地址:http://www.taobaotest.com/notices/82
#!/usr/bin/env python #coding=utf-8 import threading,urllib2,HTMLParser,time,urllib def download(url,file_name): rfile = urllib.urlopen(url) url=rfile.geturl() urllib.urlretrieve(url,file_name+".pdf") if __name__=="__main__": #lParser = parseDownloadFiles() content=urllib2.urlopen("http://www.taobaotest.com/notices/82").read() start='<h2>Tcon</h2>' end='<div class="article-nav">' content=content[content.find(start):content.find(end)] file_name_list=[] url_list=[] while 1: download_line=content[content.find("<p>"):content.find("</p>")+len("</p>")] if "down_link" in download_line: seprate=unicode("、", "utf-8") last=unicode(")", "utf-8") spec=unicode("/", "utf-8") if "<span" in download_line: file_name=download_line[download_line.find('cboxElement">')+len('cboxElement">'):download_line.find('</span>')] #if seprate in file_name: #file_name=file_name[file_name.find(u"、"):] else: file_name=download_line[download_line.find('<p>')+len('<p>'):download_line.find('(<a')] #file_name=(file_name[file_name.find(u"、"):]).strip() file_name=unicode(file_name, "utf-8") if seprate in file_name: file_name=file_name[file_name.find(seprate)+len(seprate):] if last in file_name: file_name=file_name[:file_name.find(last)] if spec in file_name: file_name=file_name.replace(spec,"") file_name_list.append(file_name) #file_name_list.append(unicode(file_name, "utf-8")) url=download_line[download_line.find('http://adc'):download_line.find('" target')] url_list.append(url) if content.find("</p>")==-1: break else: content=content[content.find("</p>")+len("</p>"):] for i in range(0,len(file_name_list)): download(url_list[i],file_name_list[i])
相关文章推荐
- 2016/01/18 Python学习1
- python爬虫模拟登录之验证码
- Python学习第四天
- 在spark上做简单的文本分类(python)
- [Python标准库]random——伪随机数生成器
- python修饰符——带参数
- Python一周学习的小结
- Python及requests乱码问题的总结
- python无参数的装饰符
- python 环境搭建(Mac)
- ML--HMM(隐马尔可夫模型及python的实现2)
- python100例(一)
- python列表和QVariant
- 《笨办法学Python》 第15课手记
- Python 基础【一】
- python数据类型-列表(序列类型)
- python collection系列
- Python_day01_笔记
- Python - 定制pattern的string模板(template) 具体解释
- Python数据类型-序列(元组)