def download_song(self, songurl, dir_path): '''根据歌曲url,下载mp3文件''' song_id, songname = self.get_songinfo(songurl) #根据歌曲url得出ID、歌名 song_url = self.get_url(song_id) #根据ID得到歌曲的实质URL path = dir_path + os.sep + songname + '.mp3' #文件路径 requests.urlretrieve(song_url, path) #下载文件 print(path) print(song_url)
def _iterate_response_chunks(self): """make request and yield response chunks""" request_response = urlretrieve(self.link, headers=self.headers, cookies=self.cookies, stream=True) request_response.raise_for_status() # only accept 200 # TODO delegate request validation to caller for chunk in request_response.iter_content(self.chunk_size): if chunk: yield chunk # generate valid chunks
def download_github_repo(url, save_path): """ 下载给定的repo,保存在本地 params@url:给定repo的网址 params@save_path:本地保存目录 """ print('processing:%s' % url) file_name = url.split('/')[-1] random_header = download_headers[randomint] response = requests.get(url, headers=random_header ) content = response.text #通过url生成zip文件链接 zip_url = generate_zip_url(url) #本地保存文件名,由于不考虑fork的repo,所以没考虑重名情况 to_file = os.path.join(save_path, file_name) + '.zip' print('file to %s' % to_file) #调用request,获取内容,并写入文件 try: requests.urlretrieve(zip_url, to_file)##将远程数据下载到本地。 except: try: with open(to_file, 'wb') as code: code.write(requests.get(zip_url).content) except: try: http = urllib3.PoolManager() req = http.request('GET', zip_url) with open(to_file, 'wb') as code: code.write(req.data) except: print(file_name + ' failed!!!!!!') print(file_name + ' done!') return
def check_or_download_inception(inception_path): ''' Checks if the path to the inception file is valid, or downloads the file if it is not present. ''' INCEPTION_URL = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz' if inception_path is None: inception_path = '/tmp' inception_path = pathlib.Path(inception_path) model_file = inception_path / 'classify_image_graph_def.pb' if not model_file.exists(): print("Downloading Inception model") # from urllib import request import requests import tarfile fn, _ = requests.urlretrieve(INCEPTION_URL) with tarfile.open(fn, mode='r') as f: f.extract('classify_image_graph_def.pb', str(model_file.parent)) return str(model_file)
def download_song(self, songurl, dir_path): '''根据歌曲url,下载mp3文件''' song_id, songname = self.get_songinfo(songurl) # 根据歌曲url得出ID、歌名 song_url = 'http://music.163.com/song/media/outer/url?id=%s.mp3' % song_id path = dir_path + os.sep + songname + '.mp3' # 文件路径 requests.urlretrieve(song_url, path) # 下载文件
def download(url, root_path): requests.urlretrieve(url, root_path) pass
from urllib.parse import quote from requests import urlretrieve qstr = quote("cerc india") do = urlretrieve("https://www.google.com/?q=" + qstr)
#-*-coding:utf-8-*- # Time:2017/9/29 15:41 # Author:YangYangJun import requests import random from urllib3 import request t1 = random.randint(800, 900) print t1 data = {'t': t1} host_url = 'http://kmustjwcxk3.kmust.edu.cn/jwweb/' captcha_url = host_url + 'sys/ValidateCode.aspx' requests.urlretrieve(captcha_url, '12.jpg') #print requests.post(captcha_url,data).text