如何批量下载pylot源码实例脚本,避免提示文件可能损害计算机?

2026-05-24 19:061阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计415个文字,预计阅读时间需要2分钟。

如何批量下载pylot源码实例脚本,避免提示文件可能损害计算机?

批量下载pylot源码示例脚本解决提示:

这类文件可能会危害您的计算机。

脚本源码:pythonimport osimport requests

定义源码下载地址列表source_urls=[ https://github.com/udacity/udacity-sdcnd/raw/master/assignments/term1/behavioral-cloning/project.py, https://github.com/udacity/udacity-sdcnd/raw/master/assignments/term1/imitation-learning/project.py, # 添加更多pylot源码链接]

保存源码的目录save_dir=pylot_source_code

创建保存目录if not os.path.exists(save_dir): os.makedirs(save_dir)

下载源码for url in source_urls: response=requests.get(url) if response.status_code==200: # 获取文件名 filename=url.split('/')[-1] # 保存文件 with open(os.path.join(save_dir, filename), 'wb') as file: file.write(response.content) print(fDownloaded {filename}) else: print(fFailed to download {url})

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

脚本源码:


getMatpoltDemo.py

如何批量下载pylot源码实例脚本,避免提示文件可能损害计算机?


#coding=utf8
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from getUrlList import getUrlList
import time,os
import urllib2

PATH=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()

运行结果:

本文共计415个文字,预计阅读时间需要2分钟。

如何批量下载pylot源码实例脚本,避免提示文件可能损害计算机?

批量下载pylot源码示例脚本解决提示:

这类文件可能会危害您的计算机。

脚本源码:pythonimport osimport requests

定义源码下载地址列表source_urls=[ https://github.com/udacity/udacity-sdcnd/raw/master/assignments/term1/behavioral-cloning/project.py, https://github.com/udacity/udacity-sdcnd/raw/master/assignments/term1/imitation-learning/project.py, # 添加更多pylot源码链接]

保存源码的目录save_dir=pylot_source_code

创建保存目录if not os.path.exists(save_dir): os.makedirs(save_dir)

下载源码for url in source_urls: response=requests.get(url) if response.status_code==200: # 获取文件名 filename=url.split('/')[-1] # 保存文件 with open(os.path.join(save_dir, filename), 'wb') as file: file.write(response.content) print(fDownloaded {filename}) else: print(fFailed to download {url})

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

脚本源码:


getMatpoltDemo.py

如何批量下载pylot源码实例脚本,避免提示文件可能损害计算机?


#coding=utf8
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from getUrlList import getUrlList
import time,os
import urllib2

PATH=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()

运行结果: