def get_url(url, parser='<STR_LIT:html>'):
url = request.quote(url, safe='<STR_LIT>')<EOL>logger.debug('<STR_LIT>', url)<EOL>req = request.Request(url, headers={'<STR_LIT>': '<STR_LIT>'})<EOL>try:<EOL><INDENT>response = request.urlopen(req)<EOL><DEDENT>except HTTPError:<EOL><INDENT>raise<EOL><DEDENT>except (ssl.SSLError, URLError):<EOL><INDENT>context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)<EOL>response = request.urlopen(req, context=context)<EOL><DEDENT>response = response.read()<EOL>if parser == '<STR_LIT:html>':<EOL><INDENT>return BeautifulSoup(response, '<STR_LIT>', from_encoding='<STR_LIT:utf-8>')<EOL><DEDENT>elif parser == '<STR_LIT>':<EOL><INDENT>return json.loads(response)<EOL><DEDENT>elif parser == '<STR_LIT>':<EOL><INDENT>return response.decode()<EOL><DEDENT>raise ValueError('<STR_LIT>')<EOL>
Requests the specified url and returns a BeautifulSoup object with its
contents.