zoukankan      html  css  js  c++  java
  • 通过脚本自动下载Esri会议材料

    在Esri的官网上,可以下载到Esri参加或者举办的各类会议的材料。官方地址为:http://proceedings.esri.com/library/userconf/index.html。

    针对某一会议,该网上往往提供会议材料清单表格,部分材料是提供下载的,例如PPT文档或者PDF文档。 

    以下脚本可用于辅助下载Esri Proceeding网站上的会议PPT,下载好的文档会自动以文档的标题重命名,这样方便检索使用。

    制定下载后存放文档的本地文件夹,预先把包含会议材料清单表格的页面使用浏览器保存到本地。

    # -*- coding:utf-8 -*-
    from lxml import etree
    from lxml.html import soupparser
    import re
    from os import path
    import shutil
    from os import rename
    from urllib.request import Request
    import urllib.request
    
    try:
        rootpath = 'D:/EsriPPT/'
        f = open('D:/Recent Proceedings.html', 'r', encoding="windows-1252", errors='ignore')
        t = ''.join(f.readlines())
        parser = etree.XMLParser(encoding='gbk', dtd_validation=False, recover=True, ns_clean=True)
        tree = soupparser.fromstring(t)
        rows = tree.xpath('//table/tbody/tr')
        for r in rows:
            cols = r.xpath('td')
            for links in cols[1].iterchildren(tag='a'):
                result = re.search(r'dev_int_d+.pdf', links.get('href'))
                if(result!=None):
                    oldpath = rootpath + result.group(0)
                    newpath = cols[0].text + '.pdf'
                    newpath = rootpath + newpath.replace(':', '_').replace('/', '').replace('?', '')
                    # to check whether the original file has downloaded
                    if path.exists(oldpath) and not path.exists(newpath):
                        rename(oldpath, newpath)
                    else:
                        remote = 'http://proceedings.esri.com/library/userconf/devsummit17/papers/' + result.group(0)
                        urllib.request.urlretrieve(remote, oldpath)
                        rename(oldpath, newpath)
    
    finally:
        f.close()
        del tree
    

      

  • 相关阅读:
    使用WCF实现消息推送
    T31P电子秤数据读取
    持续性任务代码的一些测试
    XP+Android手机DIY家庭视频点播系统-历时3周全力打造吊丝的幸福生活
    Android 上传文件到XP
    Android ListView的一个坑,你可掉进去过?
    无脑无负担网站架构-- Application Request Route的一些应用
    Android 一些注意
    懒人的ERP开发框架--2B&苦B程序员专用
    PHP Token(令牌)设计应用
  • 原文地址:https://www.cnblogs.com/luwl/p/6944957.html
Copyright © 2011-2022 走看看