Every line of 'download json file from url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
5 def download(url, file_name): 6 res = requests.get(url, stream=True) 7 if res.status_code == 200: 8 with open(file_name, 'wb') as file: 9 for chunk in res.iter_content(chunk_size=1024): 10 file.write(chunk)
84 def download_file(url, date_created, verbose=False): 85 86 filename = date_created + str(url).split('/')[-1] 87 88 if verbose: 89 print(MSG_START.format(filename)) 90 91 with open(filename, "wb") as file: 92 93 dl_time = datetime.now() 94 95 response = get(str(url)) 96 file.write(response.content) 97 98 delta = (datetime.now() - dl_time).total_seconds() 99 100 if verbose: 101 print(MSG_END.format(filename, str(delta))) 102 103 dl_time = datetime.now()
19 def download_2(url): 20 try: 21 response = requests.get(url) 22 except Exception: 23 print('Failed Download!') 24 else: 25 if response.status_code == 200: 26 with open('file_name.jpg', 'wb') as f: 27 f.write(requests.get(url).content) 28 print("Succesfully Downloaded") 29 else: 30 print('Failed Download!')
18 def download_file(url, download_path): 19 20 local_filename = url.split('/')[-1] 21 if not isfile(join(download_path, local_filename)): 22 # NOTE the stream=True parameter 23 r = requests.get(url, stream=True) 24 with open(join(download_path, local_filename), 'wb') as f: 25 for chunk in r.iter_content(chunk_size=1024): 26 if chunk: # filter out keep-alive new chunks 27 f.write(chunk) 28 f.flush() 29 print local_filename
12 def download(url, file_path, timeout=30): 13 response = requests.get(url, stream=True, timeout=timeout) 14 15 with open(file_path, "wb") as handle: 16 for data in response.iter_content(): 17 handle.write(data)
35 def download_json(self): 36 """ Download the json file from the self.com_data_full_url. 37 The save file is default to the self.saved_json_file. 38 39 """ 40 cache.clear() 41 url = URL(self.com_data_full_url) 42 f = open(self.saved_json_file, 'wb') # save as test.gif 43 try: 44 url_data = url.download(timeout = 50) 45 except: 46 url_data = '' 47 48 f.write(url_data) 49 f.close()
19 def open_json(url): 20 url = urllib.request.urlopen(url).read() 21 data_from_json = json.loads(url.decode()) 22 return data_from_json
137 @staticmethod 138 def _download(url): 139 return urllib2.urlopen(urllib2.Request(url, headers=Provider.HEADERS))
15 def get_json(url): 16 return _decode_response(urllib.request.urlopen(url))
58 def download(self, url): 59 ''' 60 下载指定url页面 61 :param url: 62 :return: 63 ''' 64 headers = { 65 'User-Agent': useragent.getUserAgent() 66 } 67 s = requests.session() 68 r = s.request(method='get', url=url, headers=headers) 69 if r.status_code == 200: 70 print('正在抓取地址:%s' % url) 71 print('User-Agent:', r.request.headers.get('user-agent')) 72 return r.content 73 return None