60 ví dụ mã Python được tìm thấy liên quan đến " kiểm tra url". Bạn có thể bỏ phiếu cho những cái bạn thích hoặc bỏ phiếu cho những cái bạn không thích và chuyển đến dự án gốc hoặc tệp nguồn bằng cách nhấp vào các liên kết phía trên mỗi ví dụ def check_url(url): """ check input url Args: url: A string represent the url which was input by user Returns: return 'vollist' if the url represent a vollist return 'book' if the url represent a book return False if the url is neither vollist nor booklist """ vollist = re.compile(r'http://lknovel.lightnovel.cn/main/vollist/(\d+).html') book = re.compile(r'http://lknovel.lightnovel.cn/main/book/(\d+).html') if vollist.search(url): return 'vollist' elif book.search(url): return 'book' else: return False def check_url_filetoupload(self): # type: () -> None """Check if url or file to upload provided for resource and add resource_type and url_type if not supplied Returns: None """ if self.file_to_upload is None: if 'url' in self.data: if 'resource_type' not in self.data: self.data['resource_type'] = 'api' if 'url_type' not in self.data: self.data['url_type'] = 'api' else: raise HDXError('Either a url or a file to upload must be supplied!') else: if 'url' in self.data: if self.data['url'] != hdx.data.filestore_helper.FilestoreHelper.temporary_url: raise HDXError('Either a url or a file to upload must be supplied not both!') if 'resource_type' not in self.data: self.data['resource_type'] = 'file.upload' if 'url_type' not in self.data: self.data['url_type'] = 'upload' if 'tracking_summary' in self.data: del self.data['tracking_summary'] def check_url(self, url, cred): if not self.is_url(url): utils.kodi_log("URL is not of a valid schema: {0}".format(url), 1) return False try: response = requests.head(url, allow_redirects=True, auth=cred) if response.status_code < 300: utils.kodi_log("URL check passed for {0}: Status code [{1}]".format(url, response.status_code), 1) return True elif response.status_code < 400: utils.kodi_log("URL check redirected from {0} to {1}: Status code [{2}]".format(url, response.headers['Location'], response.status_code), 1) return self.check_url(response.headers['Location']) elif response.status_code == 401: utils.kodi_log("URL requires authentication for {0}: Status code [{1}]".format(url, response.status_code), 1) return 'auth' else: utils.kodi_log("URL check failed for {0}: Status code [{1}]".format(url, response.status_code), 1) return False except Exception as e: utils.kodi_log("URL check error for {0}: [{1}]".format(url, e), 1) return False def check_url(url): """ Check if url has valid format or fix it :param url: string = url from option user gives :return: string = url with valid format or False """ try: # Shorter startswith https://stackoverflow.com/a/20461857 """ ftp://something.com https://something.com """ if "://" in url: if not url.startswith(("http://", "https://")): events.error("Invalid URL format") sys.exit(1) else: "Something.com" url = "http://" + url if len(url.split("/")) <= 3: url = url + "/" if url[-1] != "/" else url except: url = None return url def check_url(self): if self.start: if self.url == self.browser.url().toString(): # 授权页面url未改变 pass # 继续等待用户操作 else: if self.browser.url().toString().find('t=login_verify_entrances/w_tcaptcha_ret') > 0: # 滑块验证通过,关闭浏览器 self.start = False self.close() return elif self.browser.url().toString().find('login_verify_entrances/result') > 0: # 授权结果 time.sleep(2) # 显示结果2秒后关闭浏览器 self.close() return else: # 继续等待用户操作 pass self.timer = threading.Timer(0.1, self.check_url) self.timer.start() # 重启定时器 else: #点X关闭了浏览器 self.close() def check_url(self, data, suffix=''): # pylint: disable=unused-argument,no-self-use """ Checks that the given document url is accessible, and therefore assumed to be valid """ try: test_url = data['url'] except KeyError as ex: LOG.debug("URL not provided - %s", six.text_type(ex)) return { 'status_code': 400, } try: url_response = requests.head(test_url) # Catch wide range of request exceptions except requests.exceptions.RequestException as ex: LOG.debug("Unable to connect to %s - %s", test_url, six.text_type(ex)) return { 'status_code': 400, } return { 'status_code': url_response.status_code, } def checkURL(self): if re.search(ur"(?im)^https?://[^/]+\.[^/]+/", self.entry11.get()): #well-constructed URL?, one dot at least, aaaaa.com, but bb.aaaaa.com is allowed too if self.optionmenu11var.get() == 'api.php': self.msg('Please wait.. Checking api.php...') if dumpgenerator.checkAPI(self.entry11.get()): self.entry11.config(background='lightgreen') self.msg('api.php is correct!', level='ok') else: self.entry11.config(background='red') self.msg('api.php is incorrect!', level='error') elif self.optionmenu11var.get() == 'index.php': self.msg('Please wait.. Checking index.php...') if dumpgenerator.checkIndexphp(self.entry11.get()): self.entry11.config(background='lightgreen') self.msg('index.php is OK!', level='ok') else: self.entry11.config(background='red') self.msg('index.php is incorrect!', level='error') def load_url_and_check(self, args): """Loads the target node url from the command line, or from the last known node, or the default. Also checks connectivity to the node. """ if (args.node_url is None): if ('last_node' in self.state): url = self.state['last_node'] else: url = 'https://live.driveshare.org:8443' else: url = args.node_url self.url = url.strip('/') self.logger.info('Using url {0}'.format(self.url)) self.stats.set('node_url', self.url) self.check_connectivity() self.state['last_node'] = self.url ________số 8_______ |