批量下载pylot源码实例脚本解决提示“这种类型的文件可能会损害您的计算机。”

来源:互联网 发布:js给标签删除属性 编辑:程序博客网 时间:2024/06/05 01:07

批量下载pylot源码实例脚本解决提示“这种类型的文件可能会损害您的计算机。”


脚本源码:

getMatpoltDemo.py
#coding=utf8 from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWait from getUrlList import getUrlListimport time,osimport urllib2PATH=lambda p:os.path.abspath(os.path.join(    os.path.dirname(__file__), p))urlList=getUrlList()driver=webdriver.Chrome()  count=0     for url in getUrlList():        driver.maximize_window()    driver.get(url)    js="var q=document.body.scrollTop=200000"    driver.execute_script(js)    try:        downLoadBtnList=WebDriverWait(driver, 2).until(lambda driver:driver.find_elements_by_partial_link_text('Download'))    except Exception,e:        print "Download not exist..."        try:        if len(downLoadBtnList)>0:            for downLoad in downLoadBtnList:                         downurl=downLoad.get_attribute("href")                fileName=downurl.split("/")[-1]                filePath=PATH('./sourceCode/')                if os.path.exists(filePath):                    pass                else:                    os.mkdir(filePath)                fileWithPath=PATH(filePath+'\\'+fileName)                with open(fileWithPath,"w") as FH:                                       pageConet=urllib2.urlopen(downurl).read()                     time.sleep(1)                    print >>FH,pageConet    except Exception,e:        print "Download List is Null"                  count+=1          print count                         time.sleep(10)           driver.close()       



运行结果:


可以对比上一篇博文:http://blog.csdn.net/henni_719/article/details/77070948

阅读全文
0 0
原创粉丝点击