M
M
Mors Superberg2018-04-12 17:01:38
Python
Mors Superberg, 2018-04-12 17:01:38

How to implement such URL validation in C++?

import subprocess
import sys,validators, base64
from flask import Flask
from flask import Response
import urlparse

def get_domain(url):
  base_url = urlparse.urljoin(url, '/')
  base_url = base_url[(base_url.index('://')+3):-1]
  if base_url[:4] == "www.":
      base_url = base_url[4:]
  return base_url
  
app = Flask(__name__)
@app.route("/<url>", methods=['GET'])

def index(url):
    url = base64.b64decode(url)
    if url.find("http") < 0:
        url = "http://" + url
    if validators.url(url) == True: 
        print("Valid")
    else:
        # Check valid adress, do error heandler
        url = "https://ya.ru"
    domain = get_domain(url)
    print(url)
    print(domain)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8888)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-04-12
@NooooN

www.zedwood.com/article/cpp-boost-url-regex

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question