编写python脚本-->批量下载淘宝 2012年ADC技术嘉年华PDF文件
2016-01-18 15:20
232 查看
#!/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])
[/code]
转载于:https://my.oschina.net/u/2603916/blog/604123
相关文章推荐
- 编写python脚本-->批量下载淘宝 2012年ADC技术嘉年华PDF文件
- 批量下载淘宝 2012年ADC技术嘉年华PDF文件
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- Python批量提取PDF文件中文本的脚本
- 编写Python脚本批量下载DesktopNexus壁纸的教程
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 使用Fabric模块编写的批量同步文件的python脚本
- 利用python fabric模块写的批量操作远程主机脚本(命令执行,上传、下载文件)
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 利用Python编写脚本批量下载公众号中的音频
- 编写Python脚本批量下载DesktopNexus壁纸的教程
- Python编写shell脚本中常用的文件介绍
- 基于七牛Python SDK写的一个批量下载脚本
- python批量操作Linux服务器脚本,ssh密码登录(执行命令、上传、下载)(一)
- Python实现批量下载文件
- 【Python】pdf文件逐页转图片/修改图片存储大小脚本