0

I'm trying to make a program that checks username availability on Ubisoft.com.

I tried to do this by entering a profile URL letting the code check whether the site gives a 200- or a 404 status code, with 404 being a Taken username and 200 an Available username.

The problem with using a 200 status code for this is that the page that says it’s a 404 is in fact a 200 status code.

Does anyone know a way to make it print (“AVAILABLE”) if an username exists (like https://ubisoftconnect.com/en-US/profile/test) and print (“TAKEN”) if an username is taken (like https://ubisoftconnect.com/en-US/profile/test1241924)

The code I currently have and used for the 200 and 404 source code:

(urllib.request.urlopen("https://ubisoftconnect.com/en-US/profile/test1241924").getcode())

if (urllib.request.urlopen("https://ubisoftconnect.com/en-US/profile/test1241924").getcode()) == 200:
    print ("TAKEN")
if (urllib.request.urlopen("https://ubisoftconnect.com/en-US/profile/test1241924").getcode()) == 404:
    print ("AVAILABLE!")

2 Answers 2

0

Well first of all I'd recommend using the python requests module for this. You can implement something similar to this in urlib3 as well:

import requests

r = requests.get('https://ubisoftconnect.com/en-US/profile/test1241924')

text = r.text

if 'Nothing is broken' in text:
    print('taken')
else:
    print('available')

This is one way of doing it

Sign up to request clarification or add additional context in comments.

1 Comment

Does not work as the website always has 'Nothing is broken' as text somehow, which makes it always print 'taken'
0

urlib is a good choice but for more simple code use requests

example:

import requests
r = requests.get("https://ubisoftconnect.com/en-US/profile/test1241924")
if r.status_code == 404:
   print("Available"}
elif r.status_code == 200:
    print("Taken")

i also recommend using headers!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.